10月 192020
 

安装Django(提示已安装)

PS D:\Python> python.exe -m pip install Django
Requirement already satisfied: Django in c:\users\harveymei\appdata\local\programs\python\python39\lib\site-packages (3.1.2)
Requirement already satisfied: asgiref~=3.2.10 in c:\users\harveymei\appdata\local\programs\python\python39\lib\site-packages (from Django) (3.2.10)
Requirement already satisfied: sqlparse>=0.2.2 in c:\users\harveymei\appdata\local\programs\python\python39\lib\site-packages (from Django) (0.4.1)
Requirement already satisfied: pytz in c:\users\harveymei\appdata\local\programs\python\python39\lib\site-packages (from Django) (2020.1)
PS D:\Python> 

查看Django版本信息

import django
print(django.get_version())

PS D:\Python> & C:/Users/harveymei/AppData/Local/Programs/Python/Python39/python.exe d:/Python/hello.py
3.1.2
PS D:\Python>

命令行

PS D:\Python> python.exe -m django --version
3.1.2
PS D:\Python>

PS D:\Python> python.exe -m pip show django
Name: Django
Version: 3.1.2
Summary: A high-level Python Web framework that encourages rapid development and clean, pragmatic design.
Home-page: https://www.djangoproject.com/
Author: Django Software Foundation
Author-email: foundation@djangoproject.com
License: BSD-3-Clause
Location: c:\users\harveymei\appdata\local\programs\python\python39\lib\site-packages
Requires: sqlparse, pytz, asgiref
Required-by:
PS D:\Python>

创建项目

PS D:\Python> django-admin.exe startproject mysite
PS D:\Python> 

目录结构

mysite/             #根目录可以任意修改
    manage.py       #管理Django项目的命令行工具
    mysite/         #包名
        __init__.py #空文件,告诉Python将该目录当作python包
        settings.py #项目配置文件
        urls.py     #项目URL声明
        asgi.py     #项目运行在ASGI兼容服务器的入口
        wsgi.py     #项目运行在WSGI兼容服务器的入口

启动Django内置轻量级Web服务器

PS D:\Python> cd .\mysite\
PS D:\Python\mysite> python.exe .\manage.py runserver
Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).

You have 18 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.
October 19, 2020 - 11:43:15
Django version 3.1.2, using settings 'mysite.settings'
Starting development server at http://127.0.0.1:8000/ 
Quit the server with CTRL-BREAK.

指定监听端口

PS D:\Python\mysite> python.exe .\manage.py runserver 8080
Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).

You have 18 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.
October 19, 2020 - 11:53:53
Django version 3.1.2, using settings 'mysite.settings'
Starting development server at http://127.0.0.1:8080/
Quit the server with CTRL-BREAK.
[19/Oct/2020 11:54:05] "GET / HTTP/1.1" 200 16351
[19/Oct/2020 11:54:06] "GET /static/admin/css/fonts.css HTTP/1.1" 200 423
[19/Oct/2020 11:54:06] "GET /static/admin/fonts/Roboto-Regular-webfont.woff HTTP/1.1" 200 85876
[19/Oct/2020 11:54:06] "GET /static/admin/fonts/Roboto-Bold-webfont.woff HTTP/1.1" 200 86184
[19/Oct/2020 11:54:06] "GET /static/admin/fonts/Roboto-Light-webfont.woff HTTP/1.1" 200 85692    
Not Found: /favicon.ico
[19/Oct/2020 11:54:06] "GET /favicon.ico HTTP/1.1" 404 1972

指定监听端口和IP(0是0.0.0.0的简写)

PS D:\Python\mysite> python.exe .\manage.py runserver 0:8080

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据