app的创建和注册
APP是用来存放代码的
创建APP
命令行创建,切换到项目目录下
python manage.py startapp appo1 #app01为项目名,创建完刷新即可
目录结构
把函数放到views后,别忘了要在urls.py中导入views
from django.conf.urls import url from django.contrib import admin from appo1 import views urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^log/', views.log), url(r'^index/',views.index) ]
pycharm创建
输入命令创建
manage.py@logserver > startapp app02
修改配置,使django能够识别新建的app,修改settings中的INSTALLED_APPS
INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'appo1.apps.Appo1Config' #加上这句话 ]
创建项目时创建app,创建后无需其他配置,pycharm已经帮我们配置好了