Python version: 3.6.4
Django Version: 2.0
1 Creating an App
Input command
Python manage.py Startapp Blog
2 Create a Templates folder in the project directory for storing our web page create a index.html here
<! DOCTYPE html> "white-space:pre; "> </span><meta charset="utf-8"> <span style=" White-space:pre; "> </span><title> My Site </title>
And then the directory is like this
3 Move to Folder location: mysite/mysite/
Modify urls.py:
from django.contrib import Admin Span style= "COLOR: #0000ff" >from Django.urls import path, include from import hellourlpatterns = [path ( " , Hello.index), # Access Mys The Welcome page of ITE Path ( " admin/ " " blog/ ", include (" Blog.urls " )) #包含blog应用中的urls]
New hello.py, type content
from django.shortcuts Import Render from django.http Import httpresponse# This page deals with Project home Content Def index (request) : return HttpResponse ("Hello, python! ")
Modify settings.py
Installed_app plus our app name: Blog
TEMPLATES Add our template path DIRS
4 Move to Folder location: mysite/blog/
Modify views.py
from django.shortcuts Import Render from django.http Import httpresponse# Create your views Here.def index (Request): return HttpResponse ("Hello, World.") You ' re at the blog index. " ) def home (Request): return render (request,'blog/index.html') )
New file urls.py Typing
from django.urls Import Path from 'blog'= [ path ('index/' , Views.index), path ('home/', Views.home), ]
5 Template Location
/mysite/mysite/templates/blog/index.html
6 Restart the Uwsgi
Cd/var/www/mysite
Killall -9-X mysite.xml
Tip: Be sure to remember to restart. Otherwise it won't take effect. And it's going to restart every revision of the code.
"Python3" using Django 2.0 + python3.6.4 to create an app