django-admin startproject polls
- create a new django project namedpolls
python manage.py startserver
- start web app on localhost
pollsapp/views.py
- defineindex(request)
pollsapp/urls.py
- add url for view here
urlpatterns = [
path('', views.index, name='index'),
]
pollsproject/urls.py
- add rootURL conf herer
urlpatterns = [
path('pollsapp/', include('pollsapp.urls')), # new url
path('admin/', admin.site.urls),
]
The path
function here takes four arguments
- route
: string containing URL pattern
- view
: function to be called when pattern is matched
- name
: unique identifier for URL
INSTALLED_APPS
insettings.py
holds list of all django applications that are activatedpython manage.py createsuperuser
- create new adminpollsapp/admin.py
- contains models we want to be displayed in our admin interface
from django.contrib import admin
from .models import Question
admin.site.register(Question)
- Change your models (in models.py).
- Run python manage.py makemigrations to create migrations for those changes
- Run python manage.py migrate to apply those changes to the database.