Django Learning Note II: A project to build multiple app projects

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.