How can I learn Django 2 0
Demo address: http: //mxonline.mtianyan.cn
Tutorial warehouse address 1: https: //github.com/mtianyan/DjangoGetStarted
Tutorial warehouse address 2: https: //github.com/mtianyan/Mxonline2
Tutorial warehouse address 3: https: //github.com/mtianyan/Mxonline3
7-7 Send model form I would like to study counseling 1
The field is first validated and then saved in the database.
You can see that in our shape and in our model there are many things that are the same. How do we make code reuse?
Use modelform to solve this problem.
The include mechanism configures the application's own URL
django1.9.8 creates organization / urls.py:
django1.9.8 Mxonline2 / urls.py:
Delete the org list and add the following
django2.0.1: New organization / urls.py.
Delete org_list and add include
Use namespaces to avoid duplication
Solve the Django 2.0.1 error:
Write the app name in the urls under your app
Use the Namespace Method in HTML:
Use the model shape to send
A more reasonable operation is asynchronous and does not update the entire page.
If there is an error, an error is displayed. An asynchronous operation by Ajax.
Therefore, we currently cannot render a page back directly.
should return json data to the frontend, not the side
The class indicates what type of data is returned to the user
Configure a model form view
Configure the appropriate URL
7-8 modelform Submit I want to learn
Analyze Ajax requests
Listen to this button when the user clicks the button. Let's post a request to this url.
to serialize our form.
Add crsf_token to the form
If the status value returned by the background is "Success", it indicates the success of the submission.
fails and is written in the error field.
Checking the regular expression of the mobile number:
organization / forms.py
Submit the commit corresponding to the completion of this section:
7-7 & 8 Use modelform to fill out the asynchronous form I want to learn
7-9 Organization Details
- Institution Home
- Institutional courses
- Presentation of the agency
- Institutional lecturer
Log in to xadmin to add the required basic data. Add courses and instructors.
The course should contain a foreign key that indicates which institution it is.
courses / models.py
In Django 1.9.8:
The new foreign key field should
Because the historical data does not contain a foreign key field
Copy the four pages to org that the frontend gave us into the template
New org_base page
Take the contents of the org_home page.
- loadstaticfiles -> Change CSS file path -> Change JS file path -> Change image path
- Change the implemented URL. -> After inheriting the subpage, you need to change the place to use the block package.
Empty the homepage
When the exchange is complete, add the view and URL you visited
organization / views.py:
URL under Django 2.0.1
URL under django1.9.8:
Use the for loop in HTML to iterate over:
As shown in the above figure, you can find the field of the foreign key object directly from the foreign key field
templates / org-list.html
Configure the URL to jump to the detail page
Also back, you can replace this part of the value on the website
templates / org_base.html
The value is passed on along the inheritance chain.
Add avatar field for instructors
organization / models.py
Use the for loop to fill in data
For the same reason, we can take out the different parts of the institution's course page
Configure the access view and the URL
organization / urls.py:
Django 2.0.1 ：
Django 1.9.8 ：
organization / views.py
Change the left link of the base page
Course_org.id can be used here directly. This is because the Course_org object is passed bottom-up when rendering
Use a for loop to fill in the content.
Active change on the left
Because there is no value in determining which page is current. Pass the value back to the current page in orghomeview
Write two views
Add two urls
Under Django 2.0.1:
Under Django 1.9.8:
Change the corresponding jump link on the base page. Note: add course_org.id
Reload our page path so that breadcrumbs are displayed dynamically
7-10 Function for collecting curricula
Write the background logic of the collection:
The jQuery code for handling the collection is written in org base html
Add the favorite value to the returned page.
Similarly, add the remaining pages.
The seventh chapter is over. Corresponding commit:
7-9 & 10 & 11 & 12 completed the display of the institution details and added a collection function for course institutions. The bug when exploding when the index is not registered has been fixed
- How has the university affected your goals?
- Are dynamic languages static languages
- Why do most of my difficult questions go unanswered
- Why do you have to train
- How can I start an orchard?
- What is the future of the technical recruiter
- What can I use instead of bleach
- How does daydreaming affect thinking and creativity?
- Why are bayonets rarely attached to pistols
- What is a relay state
- How can I make friends with children
- Is data protection on the web an illusion?
- Have you ever spoken to your father
- Where should I do journalism
- What happens to the stomach when fasting
- What's carved on my violin
- Why do people become graphic designers
- Is women's basketball more popular than hockey
- How many websites use Facebook comments
- What does YG Entertainment focus on
- Is frisbee a sport or a hobby
- What is fluent in math
- What would your fear landscape look like
- Lactase is considered a protein
- What subjects do the strictest teachers have?
- Why does rejection cause obsession
- What are some relaxing ASMR sounds
- How is the faculty at daiict
- Is Pikkon a part of Universe 7
- How is social engineering successful
- What are the possible questions about table tennis
- What can a fraudster ask for besides money?