Previous Lesson: Lesson 33: Create Blogs Model in Django

Have you enjoyed creating the blog model that I told you to do first before coming to this lesson? Here’s a more important question: “Have you finished creating this blog model?” If you didn’t go back to the previous lesson; if you did, congratulations! This is how I did things to create the Blogs model in Django.

models.py

Before:

After:

settings.py

This is apps.py:

This is settings.py before:

After:

admin.py

Before:

After:

makemigrations and migrate

Terminal:

Activate your virtual environment:

Do makemigrations:

Then do migrate:

Finally, run the server:

Before on localhost:8000/admin:

This image has an empty alt attribute; its file name is Screen-Shot-2020-03-13-at-3.40.38-PM-1024x640.png

After:

Add Some Blog Posts

Click on Blogs:

ADD BLOG+:

Cool. Now let’s start filling up those fields:

Before saving this, I just want to show you something cool for a second.

Mobile View

“Mobile view?” Try to shrink your browser from your own computer. And see how cool Django stacks up things in a very nice way on a mobile device!

Cool, isn’t it?

Add Your Own Blog Posts

You can start adding some blog posts on your own now. Furthermore, your blog posts’s contents doesn’t have to be the same as mine. So be creative. I’ll just show this to you so that you won’t get surprised once you’ve seen it in the future.

This is my first blog post:

Then, this is my second:

Finally, this is my third blog post:

All in all, I now have these:

After we have made all these additions to our portfolio project, let’s do a Git commit:

Good.

What happened to my homepage?

I just want to move your attention with what we have here:

This is our homepage (localhost:8000), apparently. But when we add /admin to localhost:8000, this is what we get (localhost:8000/admin):

“Why is this happening?” Take a close look here on our urls.py and you’ll see why:

Can you recall that we have removed the path for our homepage here? Yes, that’s why. But, you may wonder: “I have seen this page error a couple of times before. Why bring it up just now?”

That’s right, I have brought this up just now and I intended to. Why? Because we have been taking care of our code on the back-end side. And I want us to focus on that side first.

But now that we are done on that side (I think), on the next lesson, we’ll be taking care of the front-end side. Hence, our homepage.

Next Lesson: Lesson 35: Back-End vs Front-End Development

Leave a Reply

Your email address will not be published. Required fields are marked *