Django - The web framework for perfectionists with deadlines
Allowed hosts
ALLOWED_HOSTS = ['*']- '*' is a wildcard that means everything
Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'pages', #app register
]- Must be added every time a new app is created
Language setting & Internationalization
LANGUAGE_CODE = 'ko-kr'
TIME_ZONE = 'Asia/Seoul'
#Internationalization
USE_I18N = True
USE_L10N = True
USE_TZ = True- A file that helps execute commands
- Do not modify!
-
apps.py: App configuration
-
admin.py: Admin view
-
models.py: Model
-
tests.py: Tests
Use specific values in URL positions as variables
# django_intro/urls.py
path('hi/<str:name>/', views.hi),
path('add/<int:a>/<int:b>/', views.add),# pages/views.py
def hi(request, name):
context = {
'name':name
}
return render(request, 'hi.html', context)<!-- pages/templates/hi.html -->
<h1>
Hi, {{name}}
</h1>Template files (HTML) can be structured using Django template language!
- Django's template language is designed to strike a balance between power and ease.
- It's designed to feel comfortable to those used to working with HTML.
{{ name }}
{{ menu.0 }}{% for option in options%}
{% endfor %}