Django first experience under Ubuntu (ii)--Create engineering and applications

Source: Internet
Author: User

First, the engineering catalogue detailed

After creating the project, get the following directory:

1. manage.py

Manage projects, create databases, start servers, etc., test, and more.

To view subcommands:

Python manage.py

Start the server:

Python manage.py runserver

Specify the address and port of the startup server:

Python manage.py runserver 0.0.0.0 8080


2. MySite Directory

2.1 settings.py for the entire site configuration. Configuration file: Application, middleware, database, static directory of various configurations ...

2.2 urls.py different URLs to different functions. URL mapping configuration file: determines which program (function) response a URL access is to.

2.3 wsgi.py The interface between the Python application or the framework and the Web server.

Second, create the application

Using apps to split functionality in Django

2.1 Creating an App Blog

Python manage.py Startapp Blog

When the creation is complete, a blog directory appears.

2.2 Adding a blog app

To add a blog to a Web site:

VI mysite/settings.py

Third, the application directory detailed

[Email protected]:~/myweb/mysite$ tree blogblog├──admin. py├──__init__. py├──migrations│└──__init__. py├──models. py├──tests. py└──views. py

3.1 views.py

Different URLs correspond to different directories, and the page is generated by views.py.

Edit views.py:

 from Import Render  from Import HttpResponse # Create your views here. def Hello (Request):     return HttpResponse ("");

To make the request call the function, also configure the URL config

"""mysite URL configurationthe ' urlpatterns ' list routes URLs to views. For more information see:https://docs.djangoproject.com/en/1.8/topics/http/urls/examples:function views 1. ADD an import:from My_app import views 2. Add a URL to Urlpatterns:url (R ' ^$ ', views.home, Name= ' home ") class-based views 1. ADD an import:from other_app.views import Home 2. Add a URL to Urlpatterns:url (R ' ^$ ', Home.as_view (), name= ' Home ') including another URLconf 1. ADD an import:from blog import URLs as Blog_urls 2. Add a URL to Urlpatterns:url (R ' ^blog/', include (Blog_urls))""" fromDjango.conf.urlsImportinclude, url fromDjango.contribImportAdminurlpatterns=[url (r'^admin/', include (admin.site.urls)), url (r'HelloWorld','Blog.views.hello'),]

Then start the server:

Python manage.py runserver

Open the browser again to get the following results:

3.2 models.py Define a table in a database

3.3 amdin.py Admin Related

3.4 test.py Test related

Django first experience under Ubuntu (ii)--Create engineering and applications

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.