Web Front end "15th" Popup Simple Use (Popup page)

Source: Internet
Author: User

First, say the self-executing function

1. What is the immediate execution function? Which is the anonymous function.

The immediate execution function is

    1. Declaring an anonymous function
    2. Call this anonymous function now

2. Example of Popup

Click to bring up a new window. After the save is finished, the page does not refresh the data and returns. (Click on the admin +, pop-up box is to do with the popup)

Specific procedures:

1, urls.py

urlpatterns = [url (r '    ^admin/', admin.site.urls),    url (r ' ^index/', views.index),    url (r ' ^pop/', Views.pop ),]

2, views.py

def index (Request):    return render (Request, "index.html") def pop (request):    if request.method== "GET":        return render (Request, "pop.html")    else:        user = Request. Post.get ("user")        print (user)        return render (Request, "pop_response.html", {"User": User})

3, Templaates

Index.html

<BODY><H1 id = "A" > Doesn't matter 


Analysis:
The first parameter of the index page is the URL, and the path you are writing to will see what page
N1: The name of the pop-up window, the dead will pop up a
'/pop/', '/pop/' a URL pops up a
If there are two + pop up two boxes

</script></body>

Pop.html

<body><form action= "" method= "post" >    {% csrf_token%}    <input type= "text" name= "user" >    <input type= "Submit" value= "Submission" ></form></body>

Pop_response.html

Run results

3, form always updated two ways

In Modelform need to know:

From APP03 import modelsfrom django.forms import Modelformclass UserForm (modelform):    class Meta:        model = models. UserInfo        fields = "__all__" After the class is found inside it, if the field in the class is FK, it is automatically generated Modelchoicefield                     if it is It will automatically generate Modelmutilchoicefield

4, Isintance and type

Class Foo (object):    passclass Bar (foo):    passobj = Bar () # isinstance used to determine if an object is an instance of the specified class (wrong) # isinstance used to judge, Whether the object is an instance of a specified class or its derived class # Isinstance print (Isinstance (obj,foo), id (obj))   #True 35558624print (isinstance (obj,bar), ID (obj))   #True 35558624print (Type (obj) ==foo)  #Falseprint (Type (obj) ==bar)  #True # think? #     object, determine if it is a type? #         If there is no inheritance relationship with Isinstance,  #         If an inheritance relationship can be used with type,  

5, The JSON supplement

Import Jsonv = {"name": "Haiyan", "age": 22}str_dic = Json.dumps (v) print (Json.dumps (v), type (str_dic))  #{"name": "\ U6d77\u71d5 "," Age ": 22}<class ' str ' >print (Json.dumps (v,ensure_ascii=false))  #{" name ":" Haiyan "," Age ": 22}

6. Reflection Example

From reflection. Settings Import Db_pathdef func ():    # import file    # reflection    # Db_path = "Db.mysql.MySQLHelper"    Module_path, Cls_name = Db_path.rsplit ('. ', maxsplit=1)    # import module as a string    # from DB import MySQL    import importlib    module _obj = Importlib.import_module (module_path)    # Go to Module import class    CLS = GetAttr (module_obj,cls_name)    # class instantiation    obj = CLS ()    obj.fetchone () if __name__ = = ' __main__ ':    func () copy Code

6. General arrangement of knowledge points

-Singleton mode-File Import-class Method-Reflection-Import a module importlib, find a class with reflection-GetAttr-object-oriented-encounters a sealed When the data is loaded, the dictionary writes a class, encapsulates the object to do-when it encounters the cyclic data: dictionaries, tuples, lists, iterative objects (__ITER__)-encountered background data processing in the page loop display, can pass Yield to do (side loop production). You can also process the recycle-request first.        GET-? name=alex&age=18&age=19 #如果遇到这样的. -Querydict type = {"Name": ["Alex",], "age": [18,19]}-to be modified. mutable = True params["hobby"] = "luning" Q          Uerydict type = {"Name": ["Alex",], "age": [18,19],hobby:["Luning"],} params["hobby"] = ["luning"] #传进去的是一个列表套列表 Querydict type = {"Name": ["Alex",], "age": [18,19],hobby:[["luning"]],}-params.setlist ("Hobby", ["luning"]) #直接把本身的元 The vegetarian pass in. querydict type = {"Name": ["Alex",], "age": [18,19],hobby:["Luning"],}-Class-component-Starksi  TE, simple interest mode, is used to save the model class and to handle the object of the configuration class for this class of additions and deletions-Starkconfig: The base class for handling additions and deletions-changelist: Encapsulates the functionality of the list page into this class- Filterrow: Create an Iterative object (__iter__), an object that holds the combined searchA row of data in-filteroption: Encapsulates the configuration item of the combined Search (database field, whether multiple selection, whether choice, condition)-Using-Class UserInfo (models.                        MOdel): ..... In stark.py class Usermodelform (modelform): Class Meta:model = Use Rinfo fields = "__all__" Class Userinfoconfig (v1.                Starkconfig) list_display ... model_form_class = Usermodelform                 V1.site.register (Userinfo,userinfoconfig)

Web Front end "15th" Popup Simple Use (Popup page)

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.