Creating an admin user
First we’ll need to create a user who can login to the admin site. Run the
following command:
You will then be prompted for your desired email address:
The final step is to enter your password. You will be asked to enter your
password twice, the second time as a confirmation of the first.
If the server is not running start it like so:
Now, open a Web browser and go to “/admin/” on your local domain – e.g.,
http://127.0.0.1:8000/admin/.
You should see the admin’s login screen:
Just one thing to do: we need to tell the admin that
$ python manage.py createsuperuser
Enter your desired username and press enter.
Username: admin
Email address: admin@example.com
Password: **********
Password (again): *********
Superuser created successfully.
Start the development server
The Django admin site is activated by default. Let’s start the development server and explore it.If the server is not running start it like so:
$ python manage.py runserver
http://127.0.0.1:8000/admin/.
You should see the admin’s login screen:
Make the poll app modifiable in the admin
But where’s our poll app? It’s not displayed on the admin index page.Just one thing to do: we need to tell the admin that
Question
objects have an admin interface. To do this, open the polls/admin.py
file, and edit it to look like this:
polls/admin.py
from django.contrib import admin
from .models import Question
admin.site.register(Question)
0 comments:
Post a Comment