421
try It yoUrself
19-1. Blog:
Start a new Django project called Blog. Create an app called blogs
in the project and a model called BlogPost. The model should have fields like
title
, text, and date_added. Create a superuser for the project, and use the
admin site to make a couple of short posts. Make a home page that shows all
posts in chronological order.
Create a form for making new posts and another for editing existing posts.
Fill in your forms to make sure they work.
Setting Up User Accounts
In this section, we’ll set up a user registration and authorization system so
people can register an account and log in and out. We’ll create a new app
to contain all the functionality related to working with users. We’ll use the
default user authentication system included with Django to do as much
of the work as possible. We’ll also modify the
Topic
model slightly so every
topic belongs to a certain user.
The users App
We’ll start by creating a new app called
users
, using the
startapp
command:
(ll_env)learning_log$ python manage.py startapp users
(ll_env)learning_log$ ls
u
db.sqlite3 learning_log learning_logs ll_env manage.py users
(ll_env)learning_log$ ls users
v
__init__.py admin.py apps.py migrations models.py tests.py views.py
This command makes a new directory called users u with a structure
identical to the
learning_logs
app v.
Adding users to settings.py
We need to add our new app to
INSTALLED_APPS
in settings.py, like so:
--snip--
INSTALLED_APPS = [
# My apps
'learning_logs',
'users',
# Default django apps.
--snip--
]
--snip--
settings.py
Do'stlaringiz bilan baham: |