Django project 14

Source: Internet
Author: User

1. prepare the project and application, enable mysql, configure admin, configure settings, and create template 2. urls [python] from django. conf. urls. defaults import patterns, include, url from django. contrib import admin. autodiscover () urlpatterns = patterns ('', url (R' ^ admin/', include (admin. site. url (R' ^ login/$ ', 'blog. views. login'),) 3. views and forms [python] # coding: utf8 from django. shortcuts import render_to_response from django import forms f Rom django. http import HttpResponse class UserForm (forms. form): name = forms. charField (initial = 'aaa', label = 'name', min_length = 4, max_length = 16) # initial can provide mail = forms. emailField () sex = forms. choiceField (choices = ('M', 'male'), ('F', 'female ') marry = forms. booleanField (required = False) birth = forms. dateField (initial = '2017-12-24 ') intr = forms. charField (widget = forms. textarea () def login (r Eq): if req. method = 'post': # bind userForm = UserForm (req. POST) # class instantiation // bind. encapsulate req in form if userForm. is_valid (): name = req. POST. get ('name') # The first method is to obtain a string. mail = userForm is not recommended. cleaned_data ['mail'] # The second method is to obtain data = userForm in python format. cleaned_data.items () # method 3 return HttpResponse (data) else: userForm = UserForm (initial = {'mail': 'A @ B .com '}) # initial in parentheses can provide the initial value return render_to_response (' Login.html ', {'userform': userForm}) 4.html [html] <body> <form action = "" method = "post"> <! -- Enter action >{{ userForm. as_ul }}<! -- UserForm's as attribute, as_p, as_table --> <input type = "submit" value = "login"> </input> </form> </body> 5. syncdb, runserver

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.