"Python3" using Django 2.0 + python3.6.4 to create an app

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.