Summary of test commands under django and windows

1. Create an application

python manage.py startapp 项目名称(test02)

2. Start the service

python manage.py runserver

You can also specify ip and port to start

python manage.py runserver 0.0.0.0:8000

3. Database migration (synchronize database)

python manage.py makemigrations

4. Data table migration (synchronize database tables)

python manage.py migrate

5. View sql statement

python manage.py sqlmigrate test02(项目名称) 0001

6、django shell

The django shell is a command line interface for django operation, and the django environment has been initialized at startup

python manage.py shell

7. Collection of static files (newly store static files)

STATIC_URL = '/static/'

## 静态文件的存储位置
STATICFILES_DIRS = [
    os.path.join(BASE_DIR,"static")
]
#STATIC_URL = '/static/'
#静态文件收集
STATIC_ROOT=os.path.join(BASE_DIR,'static')
## 静态文件的存储位置
#STATICFILES_DIRS = [
#    os.path.join(BASE_DIR,"static")
#]

 Open after collection is complete

STATIC_URL = '/static/'
#静态文件收集
#STATIC_ROOT=os.path.join(BASE_DIR,'static')
## 静态文件的存储位置
STATICFILES_DIRS = [
    os.path.join(BASE_DIR,"static")
]

 Excuting an order:

python manage.py collectstatic

 

8. Django directory introduction

manage.py:与项目进行交互的命令行工具集的接口,项目管理器
settings.py:项目的总配置文件,包含数据库、web应用、时间等各种配置
urls.py:Django项目中所有的页面都需要手动去配置URL
wsgi.py:python服务器网关接口,python应用与web服务器之间的接口,该文件在项目开发中一般不做修改
init .py:一个空文件,该目录是python包

9. Parameter introduction

from django.urls import path
from . import view

urlpatterns = [
    path('',view.index),
]

Introduction to the path function:

path(route,view,kwargs=None,name=None)
route:
the matched url will execute the corresponding second parameter view
view: used to execute the URL request matching the regular expression
kwards: the dictionary used by the view Type parameter
name: used to get the url in reverse

from django.conf.urls import url
from . import view

urlpatterns = [
    url(r'^$',view.index),
]

Introduction to url function:

url(regex,view,kwargs=None,name=None) can receive four parameters
regex: regular expression, the matching url will execute the second parameter view
view: used to execute the URL matching the regular expression Request
kwards: the dictionary type parameter
name used by the view : used to get the url in reverse

 

Guess you like

Origin blog.csdn.net/chehec2010/article/details/115189111
Recommended