PacktPublishing / Django-4-by-example

Django 4 by example (4th Edition) published by Packt
https://djangobyexample.com/
MIT License
799 stars 461 forks source link

Error with adding authors page 19 and 20 #52

Open johnscrapetest87 opened 1 year ago

johnscrapetest87 commented 1 year ago

Working thru the example in the book, on pages 19 and 20, when adding the author, I have run in to errors. Please advise.

My system is windows, Windows 10 64bit. My Python is 3.8.9 My Django is 4.2.4

I followed building the blog example exactly word for word from pages 1 thru 19. Everything is fine. At Page 19 you add the author names to the post.

Bottom of page 19 you add : "from django.contrib.auth.models import User" to models.py and on page 20 you add:

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

(note: If I hashtag out the second line above the web page works fine. So the second statement, added on page 20 is causing the error. Please advise what is causing this and advise a correction for your book for other readers.

John O'Grady

This (page 20) causes an error / exception as shown below when I load the blog site into my browser:

image.png blog_error_Page20