Introducing path search application package django-

Create an application package

 

 In settings.py registration and configuration according to the order of introduction urls.py package name and application name

settings.py

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'apps.user',
    'apps.cart',
    'apps.goods',
    'apps.orders',
)

Routing urls.py

urlpatterns = [
    url(r'^admin/', include(admin.site.urls)),
    url(r'^user$', include('apps.user.urls', namespace='user')),
    url(r'^cart$', include('apps.cart.urls', namespace='cart')),
    url(r'^orders$', include('apps.orders.urls', namespace='orders')),
    url(r'^$', include('apps.goods.urls', namespace='goods')),
    
]

If you want apps to remove, then to join the search path in the configuration file

settings.py

Import SYS 

base_dir = os.path.dirname (os.path.dirname (os.path.abspath with ( __FILE__ )))
 # were added search path 
sys.path.insert (0, the os.path.join (base_dir, ' Apps ' ) )   # need to import sys

So you can not add the apps

settings.py

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'user',
    'cart',
    'goods',
    'orders',
)

urls.py

= the urlpatterns [ 
    URL (R & lt ' ^ ADMIN / ' , the include (admin.site.urls)), 
    URL (R & lt ' ^ $ User ' , the include ( ' user.urls ' , namespace = ' User ' )),   # user module 
    URL (R & lt ' ^ $ cart ' , the include ( ' cart.urls ' , namespace = ' cart ' )),   # cart module 
    URL (R & lt ' ^ $ Orders ' , the include ( ' orders.urls ' ,namespace=' Orders ' )),   # Order module 
    URL (R & lt ' ^ $ ' , the include ( ' goods.urls ' , namespace = ' Goods ' )),   # Product Module 

]

 

Guess you like

Origin www.cnblogs.com/yifengs/p/11574119.html