Admin - Django Web Development with Python 9

sentdex · Beginner ·🔧 Backend Engineering ·10y ago

Key Takeaways

Django admin site configuration and blog post management using Python and Django framework

Full Transcript

What is going on everybody? Welcome to another Django with Python for web development tutorial. In this tutorial, what we're going to be talking about is the admin app that comes with your Django applications. So uh the first thing we need to do if we want to utilize the admin is um as you'll see if we go to our website okay and you want to go to admin you just do slashadmin and you get here and then you start thinking hm uh what do I do now admin right so you don't have an admin you don't know what the login is so the first thing you have to do is actually create a super user or an admin so that's what we're going to do first so we're going to go and break the running server and we'll go up here and get manage.py. And what we want to do is python manage.py create super user. Hit enter. And then now you can define the user. I'll just call mine admin. Email address uh hskinsleyhmail.com. Password whatever you want it to be. I think I picked a pretty pretty good one. Okay, got our user and I need to log in before I forget the password. So, we'll come over here and the username will be admin. Oh, wait, hold on. We need to uh run the server. Create super user. So, manage.py run server. Uh, and now what we want to do is log in. So you'll go, you know, your your website/admin password. [Music] Good. Okay. So once you've done that, you log in. This is the Django administration. So you'll see here that you've got uh groups and you've got users in here. Uh and then what you could do is, you know, you can click on groups for example there. We don't have any groups, but you could like plus add a group and do fancy stuff here. And you can go into users and look at that. There we are. And we could set um you know are we an active user. If you uncheck this, it's basically the equivalent of deleting an account. It doesn't delete the account, but it doesn't let them log in. Staff status, super user status. You can create custom groups and give very specific custom user uh permissions. What can they this user actually do? You've got all this stuff. Blah blah blah. Okay, cool. But we don't really care that much about that. What we really want is well, we want a pony, right? We want to be able to access our blog table basically here uh and edit the blog, post blogs, do everything via this administration panel, okay? Because we want a pony. So, what we're going to do is uh first we have to admit that we're not going to get a pony, but Django is going to give us something close to a pony. So, what we're going to do is we're going to go into blog and you should already have an admin.py file. Go ahead and open that up. And you'll see that we're importing some stuff naturally. And then you can register your models here. So what we're going to do is from blog.models import posts. So that's our post class which defines that table and all that fun stuff. Now what we're going to do is simple admin.register register and we register post. Save that. Come back to your admin panel. Go back to the home. Boom. There's post. Oh my goodness. So now you can see that we got add and change. And we can also click, but there's zero post. But then we can also add a post here. So let's go ahead and add a post. Hermager Django is awesome. Wow. Wow. Wow. Wow. Wow. Okay. And then for date, what's cool is you can very quickly just say today right now. And uh save and add another. Let's say is today really December. Oh my goodness, it's December. Anyway, probably by the time anybody's seeing this, it'll be even later. Anyway, uh save. And you can either save and continue editing. You can save and add another. Or you could just save. And we'll save and add another. And um then we'll say amazing grace today and now. Save and add another uh hello world. Good. Hia. And then we'll do today and now. But you can also do like this like you could say uh this post was back in September. Okay. Save. All right. So now these are our admin, blog, and posts. So let's go back home. And you would like if you just logged in admin, you'd see this. You could click on post, see like, okay, cool. Here's all our posts. Hello world and blah blah blah. And you could edit it. You could delete it. You could save and continue editing and save and add another. Cool. So now, what if we just go to our homepage and we click on blog. There's our information, right? It's just there. And sure enough, the titles are links. And in our excitement, we click on one and ah, it doesn't work. Why doesn't it work, you ask? Well, of course, we don't have any URL path that explains uh or works with slashblog/2. We can even see, well, at least here's slashblog, but this is the homepage, right? It required it to be slashblog, not slashblog 2. So, now what we have to do is create uh the handling. We need the URLs. We need a view um for the individual posts. So, um that's what we're going to be covering in the next tutorial. This one should be quick and easy. Quick and painless, easy enough for you guys to get up to this point. But if you had any problems, uh feel free to leave them below. One thing to keep in mind, if this is the first time you visited the admin, which if you're following along, it probably was. If it didn't work for whatever reason, you can always go to my site, go to settings, and make sure admin is installed. So you'd come down here, make sure that you have this line. It should be there by default. Um, but if it's not there for whatever reason, you might need to add that part. Okay, so uh that's that. As always, thanks for watching. Thanks for all the support, subscriptions, and until next time.

Original Description

In this 9th Django web development with Python tutorial, we're going to cover the admin page, along with adding some blog posts to our application. Just when you thought you've seen most of the backend magic that Django has to offer, there's more! The Django admin site/app is pretty incredible. This is your Admin Control Panel, and it's already done. Just like Django handles your database work with the models.py, your Admin page is going to work very much in the same way. To access the admin page, you visit /admin/, assuming the admin app is indeed installed. Sample code and text-based tutorial: https://pythonprogramming.net/admin-django-python-tutorial/ https://pythonprogramming.net https://twitter.com/sentdex https://www.facebook.com/pythonprogramming.net/ https://plus.google.com/+sentdex
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from sentdex · sentdex · 0 of 60

← Previous Next →
1 Matplotlib Python Tutorial Part 1: Basics and your first Graph!
Matplotlib Python Tutorial Part 1: Basics and your first Graph!
sentdex
2 Python Encryption Tutorial with PyCrypto
Python Encryption Tutorial with PyCrypto
sentdex
3 Python's Logging Function
Python's Logging Function
sentdex
4 wxPython Tutorials 1: Making Windows GUIs with Python : Installing + 1st window!
wxPython Tutorials 1: Making Windows GUIs with Python : Installing + 1st window!
sentdex
5 wxPython Tutorials 2: Making Windows GUIs with Python: Customizing Window Parameters
wxPython Tutorials 2: Making Windows GUIs with Python: Customizing Window Parameters
sentdex
6 wxPython Programming Tutorial 3: Menu Bar and Menu Button
wxPython Programming Tutorial 3: Menu Bar and Menu Button
sentdex
7 wxPython Programming Tutorial 4: Panels
wxPython Programming Tutorial 4: Panels
sentdex
8 wxPython Programming Tutorial 5: User Input Saved To Variables
wxPython Programming Tutorial 5: User Input Saved To Variables
sentdex
9 wxPython Programming Tutorial 6: Multiple Choice Input
wxPython Programming Tutorial 6: Multiple Choice Input
sentdex
10 wxPython Programming Tutorial 7: Adding Static Text and Colors
wxPython Programming Tutorial 7: Adding Static Text and Colors
sentdex
11 wxPython Programming Tutorial 8: Custom Button Images
wxPython Programming Tutorial 8: Custom Button Images
sentdex
12 wxPython Programming Tutorial 9: Tool Bar Items and Sub Menus!
wxPython Programming Tutorial 9: Tool Bar Items and Sub Menus!
sentdex
13 Basic PHP Tutorial 13: Multi-dimensional Array
Basic PHP Tutorial 13: Multi-dimensional Array
sentdex
14 Basic PHP Tutorial 15: Functions and Global Variables
Basic PHP Tutorial 15: Functions and Global Variables
sentdex
15 Basic PHP Tutorial 12: Associative Array
Basic PHP Tutorial 12: Associative Array
sentdex
16 Basic PHP Tutorial 14: Foreach loop
Basic PHP Tutorial 14: Foreach loop
sentdex
17 Basic PHP Tutorial 16: Include and Require
Basic PHP Tutorial 16: Include and Require
sentdex
18 Basic PHP Tutorial 7: Assignment, comparison and Logical operators
Basic PHP Tutorial 7: Assignment, comparison and Logical operators
sentdex
19 Basic PHP Tutorial 4: Variables and Comments
Basic PHP Tutorial 4: Variables and Comments
sentdex
20 Basic PHP Tutorial 11: Arrays part 1, basic array
Basic PHP Tutorial 11: Arrays part 1, basic array
sentdex
21 Basic PHP Tutorial 6: If else and else if conditionals cont'd
Basic PHP Tutorial 6: If else and else if conditionals cont'd
sentdex
22 Basic PHP Tutorial 1: Intro to PHP
Basic PHP Tutorial 1: Intro to PHP
sentdex
23 Basic PHP Tutorial 3: HTML with PHP
Basic PHP Tutorial 3: HTML with PHP
sentdex
24 Basic PHP Tutorial 9: While Loop
Basic PHP Tutorial 9: While Loop
sentdex
25 Basic PHP Tutorial 10: Switch Statement
Basic PHP Tutorial 10: Switch Statement
sentdex
26 Basic PHP Tutorial 2: Print and Echo
Basic PHP Tutorial 2: Print and Echo
sentdex
27 Basic PHP Tutorial 5: If else and else if conditional statements
Basic PHP Tutorial 5: If else and else if conditional statements
sentdex
28 Basic PHP Tutorial 8: Arithmatic Operators: Doing math with php
Basic PHP Tutorial 8: Arithmatic Operators: Doing math with php
sentdex
29 Basic PHP Tutorial 17: User Input Form Example / String Manipulation
Basic PHP Tutorial 17: User Input Form Example / String Manipulation
sentdex
30 Basic PHP Tutorial 18: HTML Entities and forms cont'd
Basic PHP Tutorial 18: HTML Entities and forms cont'd
sentdex
31 Basic PHP Tutorial 19: Finding words in strings
Basic PHP Tutorial 19: Finding words in strings
sentdex
32 Basic PHP Programming Tutorial 20: Saving to a File / writing and appending
Basic PHP Programming Tutorial 20: Saving to a File / writing and appending
sentdex
33 Basic PHP Programming Tutorial 22: Hashing part 2: salting
Basic PHP Programming Tutorial 22: Hashing part 2: salting
sentdex
34 Basic PHP Programming Tutorial 23: Variables in Strings and tokenizing
Basic PHP Programming Tutorial 23: Variables in Strings and tokenizing
sentdex
35 Basic PHP Programming Tutorial 21: MD5 Hashing For Security
Basic PHP Programming Tutorial 21: MD5 Hashing For Security
sentdex
36 Basic PHP Programming Tutorial 24: String similarity
Basic PHP Programming Tutorial 24: String similarity
sentdex
37 Basic PHP Programming Tutorial 25: Time and Time stamps
Basic PHP Programming Tutorial 25: Time and Time stamps
sentdex
38 Basic PHP Programming Tutorial 26: Die and Exit
Basic PHP Programming Tutorial 26: Die and Exit
sentdex
39 Basic PHP Programming Tutorial 27: MySQL Databases Part 1
Basic PHP Programming Tutorial 27: MySQL Databases Part 1
sentdex
40 Basic PHP Programming Tutorial 28: MySQL Database Part 2: Reading From Database
Basic PHP Programming Tutorial 28: MySQL Database Part 2: Reading From Database
sentdex
41 Basic PHP Programming Tutorial 29: MySQL Database Part 3: Inputting Data
Basic PHP Programming Tutorial 29: MySQL Database Part 3: Inputting Data
sentdex
42 Basic PHP Programming Tutorial 30: MySQL database in Use
Basic PHP Programming Tutorial 30: MySQL database in Use
sentdex
43 Django Tutorial Web Development with Python Part 1: Installing Django
Django Tutorial Web Development with Python Part 1: Installing Django
sentdex
44 Python Tutorial: File Deletion and Folder Deletion / directory deletion
Python Tutorial: File Deletion and Folder Deletion / directory deletion
sentdex
45 Python Tutorial: How to Rename Files and Move Files with Python
Python Tutorial: How to Rename Files and Move Files with Python
sentdex
46 3D Graphs in Matplotlib for Python: Basic 3D Line
3D Graphs in Matplotlib for Python: Basic 3D Line
sentdex
47 3D Plotting in Matplotlib for Python: 3D Scatter Plot
3D Plotting in Matplotlib for Python: 3D Scatter Plot
sentdex
48 3D Charts in Matplotlib for Python: Multiple datasets scatter plot
3D Charts in Matplotlib for Python: Multiple datasets scatter plot
sentdex
49 Sikuli Tutorial 1: Visually programming in python!
Sikuli Tutorial 1: Visually programming in python!
sentdex
50 Sikuli Tutorial 2: Program visually in python!
Sikuli Tutorial 2: Program visually in python!
sentdex
51 Sikuli Tutorial 3: Program visually in python!
Sikuli Tutorial 3: Program visually in python!
sentdex
52 3D Bar Charts in Python and Matplotlib
3D Bar Charts in Python and Matplotlib
sentdex
53 3D Plane wire frame Graph Chart in Python
3D Plane wire frame Graph Chart in Python
sentdex
54 Raspberry Pi Part 1 Introduction
Raspberry Pi Part 1 Introduction
sentdex
55 Raspberry Pi Part 8: First Download and Update! (Firmware)
Raspberry Pi Part 8: First Download and Update! (Firmware)
sentdex
56 Raspberry Pi Part 10: How to set up a Linux Web Server on your Pi
Raspberry Pi Part 10: How to set up a Linux Web Server on your Pi
sentdex
57 Raspberry Pi Part 11: Remote Desktop
Raspberry Pi Part 11: Remote Desktop
sentdex
58 Twitter Analysis: How to rank a user's influence
Twitter Analysis: How to rank a user's influence
sentdex
59 GPIO Tutorial for Pi Part 2 - Programming the GPIO
GPIO Tutorial for Pi Part 2 - Programming the GPIO
sentdex
60 GPIO Tutorial for Raspberry Pi Part 1 - Setting up
GPIO Tutorial for Raspberry Pi Part 1 - Setting up
sentdex

This tutorial covers the configuration of the Django admin site and management of blog posts using the admin panel. It also touches on the creation of a superuser, registration of models, and handling of URLs in Django.

Key Takeaways
  1. Create a superuser using python manage.py createsuperuser
  2. Configure the admin site by registering models in admin.py
  3. Manage blog posts using the admin panel
  4. Handle URLs for individual blog posts
  5. Create a view for individual blog posts
💡 The Django admin site provides a powerful interface for managing data models, including blog posts. By registering models and configuring the admin site, developers can easily manage data and perform CRUD operations.

Related AI Lessons

Up next
This Cop Was Held Accountable For His Brutality! #police #lawyer
Hampton Law
Watch →