Create a Python Django development framework

Source: Internet
Author: User
Tags url forwarding

Establish a Python Django development framework to verify the effectiveness of forms. You can easily generate corresponding forms from your defined model instances. You can follow them to experience Django's beauty step by step and use Django's powerful and scalable template language, the design, content, and Python code can be separated. And can be inherited.

Therefore, you cannot fully understand or understand all the form details in the Python Django development framework, I do feel that django's practice of creating a form from a model is quite limited. In many cases, the data in the model is not from the page. In this case, after the form object is constructed, ahuaxuan has not found the method to modify the median of the form.

The custom form class is also troublesome, that is, to write your own model. This is different from our previous practice. Here, form represents the value object in java, and model is the domain object, in our ssh framework, we usually inherit the value object from our domain object.

Although a bunch of people have raised objections and said they want to separate the two objects because they are at different levels, we can see from practical experience that, there is nothing wrong with this. However, the separation of custom form and model in django may be in line with the psychology of some people. However, Custom forms are also commendable. In form, we can customize verification rules.

At the same time, we can directly generate content on the page based on the form object, but this is also a bit of a hassle, that is, it is more troublesome to change the style. However, in general, django's form is quite characteristic, and it brings us convenience to a certain extent.

In the Python Django development framework, url Forwarding is based on regular expressions. Some people call it poor, and some call it poor. Url forwarding should be very clear and bright, but after using this regular expression to match something, I am depressed.

So I can only go back to the distant past to bypass this stuff. I don't need to always do it. According to the current knowledge, what is in django's views is actually controller. Why is it called views? I don't know, but it has always been like this, even in nature.

A lot of things are not quite the same on the surface. In fact, the internal principle is the same. I think django's views are the actions in struts1.x. Why, let's take a look at the two comparison codes. The first part is django and the second part is struts1.x:

 
 
  1. def index(request):     
  2.          
  3.     categoryList = Category.objects.filter(enable = True)     
  4.     for cate in categoryList:     
  5.         informationList = Information.objects.filter(catecategory = cate)[0:5]     
  6.         cate.informationList = informationList     
  7.              
  8.     c = Context({"categoryList":categoryList})     
  9. return render_to_response(indexPage, c)   

In terms of form, the two are surprisingly similar, such as input parameters. We know that python is an object-oriented language, but in fact it also supports function programming. If def is defined within the class, it is the object method. Otherwise.

It can be thought of as function programming. Let's look at it. Everything in our Python Django development framework is a function. views is actually a module. We can think of this module as an action in struts1.x, the functions in views can be considered as methods in action. They are distant relatives.

  1. How to embed Python into C ++ applications?
  2. In-depth discussion of Ruby and Python syntax comparison
  3. Introduction to Python
  4. Python Learning Experience: version, IDE selection and encoding solution
  5. Analysis of Python GIL and thread security

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.