1. Create a python virtual environment and install django
2. Create a django project
Order:django-admin startproject 项目名称
eg:
G:\django_learn>workon testvir
(testvir) G:\django_learn>django-admin startproject django_learn
When the execution is complete, a django project will be successfully created django_learn
and the directory will be generated
--- django_learn
---settings.py
---url.py
---wsgi.py
--- manage.py
settinngs.py
Contains the default settings for the project, including database information, debug flags, and other variables that workurl.py
Responsible for mapping URL patterns to applicationswsgi.py
Responsible for the launch of the projectmanage.py
Tools in the Django project, through which you can call the django shell and database.
3. Create an app
Order:python manage.py startapp 应用名
eg:
(testvir) G:\django_learn\django_learn>python manage.py startapp blog
(testvir) G:\django_learn\django_learn>dir
Successfully created an app named blog containing
admin.py
apps.py
migrations
models.py
tests.py
views.py
__init__.py
views.py
View Action File
Fourth, use django to make the first page
Configure the settings.py file to import the app into it
INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'blog' # 将blog导入settings.py ]
Configure the url.py file and set the route
from django.conf.urls import url from django.contrib import admin from blog import views urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^time_show/', views.time_show), ]
Configure views.py, set the view
import time from django.shortcuts import HttpResponse # Create your views here. def time_show(request): return HttpResponse(time.asctime())
5. Start the django project
Command: python manage.py runserver
default port 8000
eg:
(testvir) G:\django_learn\django_learn>python manage.py runserver
Performing system checks...
System check identified no issues (0 silenced).
You have unapplied migrations; your app may not work properly until they are applied.
Run 'python manage.py migrate' to apply them.
May 03, 2018 - 22:54:14
Django version 1.9.8, using settings 'django_learn.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
Enter http://127.0.0.1:8000/time_show/ in the browser to
display the following picture