Django Project 10

Source: Internet
Author: User

Preparation [plain] service mysqld start create database web10 default character set utf8; django-admin.py startproject web10 django-admin.py startapp blog admin. py create settings configure [python] DATABASES = {'default': {'Engine ': 'django. db. backends. mysql ', 'name': 'web10', 'user': 'root', 'Password': '', 'host':'', 'Port ': '', }} TIME_ZONE = 'Asia/Shanghai' using age_code = 'zh-cn' MEDIA_ROOT = '. /upload/'# media files In this folder, the url path of MEDIA_URL = '/mytes/' # media_root ing INSTALLED_APPS = ('django. contrib. auth ', 'django. contrib. contenttypes ', 'django. contrib. sessions ', 'django. contrib. sites ', 'django. contrib. messages ', 'django. contrib. staticfiles ', 'blog', 'django. contrib. admin ',) models configuration [python] # coding: utf8 from django. db import models from django. contrib import admin sex_choices = ('M', 'male'), ('F', 'fema Le ') class Emp (models. model): name = models. charField (verbose_name = u'name', max_length = 20) sex = models. charField (choices = sex_choices, max_length = 1, verbose_name = u 'gene') birthday = models. dateField () headImg = models. fileField (upload_to = '. /headimg/') # A field is added here. synchronization is ineffective and it is troublesome to go in, so you can delete and recreate it. Class Meta: ordering = ['name'] # internal class EmpAdmin (admin. modelAdmin): # This class is only used to modify the Emp class. Therefore, when registering the class, pay attention to sticking it to a piece of list_display = ['name', 'sex ', 'birthday'] search_fields = ['name', 'sex'] list_filter = ['birthday'] class New (models. model): title = models. charField (max_length = 100, verbose_name = u'title') content = models. textField (verbose_name = u'news') def _ unicode _ (self): return self. title uls configuration [python] from django. conf. Urls. defaults import patterns, include, url from django. contrib import admin. autodiscover () urlpatterns = patterns ('', url (R' ^ admin/', include (admin. site. urls),) admin. py registers [python] from django. contrib import admin from blog. models import Emp, EmpAdmin, New admin. site. register (Emp, EmpAdmin) # Here, Emp is registered with EmpAdmin, while New is registered separately, because EmpAdmin modifies Emp. Admin. site. register (New) writes data to the database. After the server runs [plain] python manage. py syncdb python manage. py runserver, you can go to the management interface to perform operations. This project adds Chinese processing, sorting processing, various field processing, built-in class processing, modifier class processing, and query processing to the previous project.

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.