#如何实现这样的功能呢? 让多个app 集合在一个apps的目录下呢?
import os import sys # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) sys.path.insert(0,os.path.join(BASE_DIR,'apps'))
INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'user', #用户模块 'goods', #商品模块 'cart', #购物车模块 'order', #订单模块 ]
如何在项目内新建一个app模块呢?
pycharm 内找到 Tools ------ Run manage.py Task 点击触发运行 输入: startapp + "app名字" 即可
#其次做url分发:
from django.conf.urls import url,include from django.contrib import admin urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^user/', include('user.urls',namespace='user')), url(r'^cart/', include('cart.urls',namespace='cart')), url(r'^order/', include('order.urls',namespace='order')), url(r'^', include('goods.urls',namespace='goods')), ]
# 注意有多个app共存的话, 模板层渲染会出问题, 需要在settings做配置,配置如下
TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [os.path.join(BASE_DIR, 'templates')] , 'APP_DIRS': True,