After reading "Learn Python Django with Lao Qi"

1. Tell me about this book, the explanation is very detailed, and the content selection is enough to get started with Django.

2. A few points to note when studying this book:

<1>If you want to follow the code of this book, you must install: Django version 1.10.1 (of course you can also play the new version of Django2, some parts in the middle need to be solved by yourself) and the following:

sudo pip3 install django==1.10.1

sudo pip3 install pytz

sudo pip3 install django-password-reset

sudo pip3 install redis

sudo pip3 install Markdown

sudo pip3 install Pillow

sudo pip3 install sorl-thumbnail

sudo pip3 install django-braces

sudo pip3 install awesome-slugify

<2> The source code download address of this book: https://github.com/qiwsir/DjangoPracticeProject

Let's talk about the source code: if it is installed according to <1>, there will be basically no problem with the imported package, because this project is developed for Django1.10.

where the basics are wrong

>1 login.html

in source code
<p style="margin-top:10px">Forgot your password? <a href="{% url 'pwd_reset' %}">reset password</a></p>
</div>
改为如下:
<p style="margin-top:10px">Forgot your password? <a href="{% url 'pwd_reset:password_reset_recover' %}">reset password</a></p>
</div>

>2 This error is a database problem error: when creating a many-to-one relationship, you need to add on_delete=models.CASCADE to the second parameter of Foreign. This is a cascading delete in the primary and foreign relationship keys , that is, when deleting When the data of the main table is deleted, the data from the table is also deleted along with it.

models in the account application  

user = models.OneToOneField(User, unique=True, on_delete=models.CASCADE) 
user = models.OneToOneField(User, unique=True, on_delete=models.CASCADE)

models in the article app

user = models.ForeignKey(User, related_name='article_column', on_delete=models.CASCADE)
author = models.ForeignKey(User, related_name="tag", on_delete=models.CASCADE)

models in a blog application

author = models.ForeignKey(User, related_name='blog_posts', on_delete=models.CASCADE)

models in the course application

user = models.ForeignKey(User, related_name='lesson_user', on_delete=models.CASCADE)
course = models.ForeignKey(Course, related_name='lesson', on_delete=models.CASCADE)

models in the image app  

user = models.ForeignKey(User, related_name="images", on_delete=models.CASCADE)

<3> After modification, run python manage.py makemigrations to create a data table

       Run python manage.py migrate to create the database

<4> According to the above modification, the source code can be run

Python manage.py runserver

Of course, if you want to enter the background management, you need to create a super administrator yourself

python manage.py createsuperuser

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324723671&siteId=291194637