基础命令:
django-admin startproject name #启动项目
django-admin startapp name #建立一个APP
python manage.py makemigrations #建立数据库迁移准备
python manage.py migrate #迁移
单个APP的项目目录:
SETTING.PY注意基本配置:
数据库(用的MYSQL):
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', # 或者使用 mysql.connector.django
'NAME': 'test',
'USER': 'test',
'PASSWORD': 'test',
'HOST':'test',
'PORT':'3306',
}
}
静态文件路径:
STATIC_URL = '/static/'
#STATIC_ROOT = os.path.join(BASE_DIR,'static')
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
中文:
LANGUAGE_CODE = 'zh-hans'
上传路径:
MEIDA_ROOT = BASE_DIR+"/upload/"
项目urls的配置,采用include,通过只要,使vote开头的URL都到指定应用中去。
from django.contrib import admin
from django.conf.urls import include,url
urlpatterns = [
url('admin/', admin.site.urls),
url(r'^vote/',include('vote.urls'))
]
url使用path可以获取相应的字段。具体可参考:https://www.cnblogs.com/huang-yc/p/9651162.html
from django.conf.urls import url,re_path
from . import views
from django.urls import path
urlpatterns = [
path('<str:vname>/index', views.index),
path('<str:vname>/search-post', views.search_post),
]
到此,基本的配置好了。
正文完