Django allows multiple apps to exist in a project, such as a large portal that can contain forums, news, and so on, each of which is called an app, and can be understood as a separate, small project that is ultimately integrated in a portal to be presented to the user
This test is based on the Python 2.7 PYCHARM5 environment
First build the project, project name: Testdjango
Secondly, we set up the corresponding app module: Todo,oa,web
:
Locate the Testdjango folder in the Testdjango project, open the urls.py routing profile, and add the following configuration
FromDjango.conf.urlsImport Url,include
FromDjango.contribImport Admin
From Web.viewsimport index
urlpatterns = [
URL (r ' ^admin/', include (Admin.site.urls)),
URL (r ' ^$ ', index,< Span style= "color: #660099;" >name= ' index '),
URL (r ' ^todo/', include ( ' Todo.urls '),
URL (r ' ^oa/', include ( ' Oa.urls '),
URL (r ' ^web/', include ( ' Web.urls ')),
]
and import the index function, which is set up in the views file of index in Todo,oa,web
An open default home page is also specified, which is the index under the web app;
from web.views import index
URL (r ' ^$ ', Index,name= ' index '),
Span style= "color: #000000;" > Open the views.py file under the Web app and the Oa,todo app and write the following code
Import Render
Import *
# Create your views here.
def index (request):
Return HttpResponse ("web")
At this point, run the program, page
If the path entered at this time islocalhost:8000/web/inex , Localhost:8000/oa/inex,localhost:8000/toto/index will be presented with different apps, and it needs to be configured for the URLs in each of their sub apps, as shown below
Import URL
Import Admin
Import *
Urlpatterns = [
URL (R ' ^index/$ ', index,name=' index '),
]
Django Learning Note II: Multiple app projects for a single project build