Python Django 1.Hello Django

Source: Internet
Author: User
Tags install django pip install django

#安装Django
Pip Install Django #== version number
#选择路径:
D:
#任意文件夹名

CD Django

#罗列Django所提供的命令, where the startproject command to create the project

Django-admin

#新建一个名为guest的项目
Django-admin Startproject Guest

#进入guest
CD Guest
Python manager.py# View the commands provided by manage
Create an App #startapp command
#创建sign应用
Python manage.py Startapp Sign
#运行项目
#python manage.py runserver #可添加地址及端口eg: 127.0.0.1:8000
#访问127.0.0.1:8000
#显示It worked!
#配置guest the/setting.py file to add the sign app to your project
#INSTALLED_APP里添加创建应用, sign
#添加完毕后直接访问127.0.0.1:8000/index, actually page not found
#guest/urls.py Configure access paths,
URL (r ' ^index/$ ', views.index), #urlpatterns里添加
#注意如果urls里面就这么写, actually can not find views, but also need to add the following sentence:
From sign import views
#.. /gign/views.py adding functions
From django.http import HttpResponse

#Create your views here
def index (Request):
Return HttpResponse ("Hello Django")
#但是这样直接访问的是urls里面的方法
#这样, we annotate all the above methods, and write a new
#新建一个index方法
From django.shortcuts Import Render

def index (Request):
return render (Request, "index.html")
#写到这里, not really, because there is not a corresponding index.html to access
#于是我们在sign应用里, create a new templates directory, and Django finds this directory by default
#在templates目录下, create a new index.html
<title>django page</title>
<body>
</body>
Complete a full Django Hello Django workflow at this point;

The Django workflow actually points to sign/views.py from guest/urls.py and executes the request based on the method

Python Django 1.Hello Django

Related Article

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.