Django~newproject and APP

Source: Internet
Author: User

New Project

1. New Django-admin startproject MySite

2. Running manage.py runserver 8080

New APP

1.manage.py Startapp Polls

2.write View.py:def index and so on

3.create urls.py:urlpatterns=[URL ()]

4.url linking to Project: Modifying Add mysite/urls.py,

URL (r ' ^polls/', include (' Polls.urls ')),

5. Installing the database manage.py migrate

6.creating Models

7.Activating models add a row in mysite/settings.py

8 Creating a compilation manage.py Makemigrationgs polls

Modify the compilation manage.py migrate

9 operation, input data

manage.py Shell

Import Django

Django.setup ()

-------------

From Polls.models import Question,choice

Question.objects.all ()

From django.utils import timezone

Q = Question (question_text= "What ' s new?", Pub_date=timezone.now ())

More Vies

1.vies.py New DEF detail results vote

2.polls/urls.py new URL

Adding template templates

1. Create a new template/app/index.html under the app's file

2. Editing HTML files

3. Update polls/views.py

New 2 APPS

1.manage.py Startapp POLLS2, adding registrations in project

2.copy polls templates, new folder modify app name

3.copy Modify Models,

4. Modify URLs.

5. Edit views

Major all polls modified to POLLS2

The App_name in urls.py

A lot of views.py in the

And in the xxx.html.

Make the poll app modifiable in the admin?

Add model in polls2/admim.py

From Django.contrib import adminfrom. Models import Questionadmin.site.register (Question)

ListView and DetailView

We ' re using the generic views here: ListView and DetailView . Respectively, those, the concepts of "display a list of objects" and "display a detail page for a partic Ular type of object. "

General view

In addition to Object_list, Django offers a number of common view functions, distributed in several modules: Django.views.generic.list_detail module

    • Object_list displaying a list of model objects
    • Object_detail displaying a single Model object
Django.views.generic.create_update Module
    • Create_object Creating Model objects
    • Update_object Modifying Model objects
    • Delete_object Deleting Model objects
Django.views.generic.simple Module
    • Direct_to_template renders a given context object directly using the specified template
    • Redirect_to Redirect to the specified URL
django.views.generic.date_based Module

This module mainly deals with the function of "View Archive by Time", which originates from the press and publishing industry. Details include:

    • Archive_index top-of-the-list archive with the latest objects for all years and a specified number
    • Archive_year Archive by year, listing all the months that have objects
    • Archive_month is archived monthly, listing all objects of the month, finding the previous, next month that owns the object
    • Archive_week Archive by week, listing all objects of the week
    • Archive_day Archive by day, listing all objects of the day, finding the previous, next date that owns the object
    • Archive_today Daily archive of current date (today)
    • Object_detail show objects found by year/month/day/ordinal

Django~newproject and APP

Related Article

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.