Python Django Tutorial: Full-Featured Web App Part 1 - Getting Started

Corey Schafer · Beginner ·🔧 Backend Engineering ·7y ago

Key Takeaways

This video tutorial series covers the basics of building a full-featured web application using the Django framework, including setting up a new project, creating a basic application, and running the development server. The tutorial uses tools such as Django, Python, pip, and Sublime Text to demonstrate the process.

Full Transcript

hey there how's it going everybody in this series of videos were going to be learning how to build a full-featured web application using the Django framework and Python so Django is a very popular framework that gives us a lot of functionality right out of the box and makes it really enjoyable to work with these web applications so first let me show you what will be building in this series of videos and then we'll get started learning how to actually put all of this together so this is the application that we'll be building here and you can see that it's a blog style of an application where different users can write different posts now this can be like blog post or they can be Twitter updates or whatever it is that you want to do with this now we have an authentication system so I'm logged in right now so we can log out and if we go to register then new users can create a new account if you already have an account then you can login and we can see at the login page we have this forgot password link now that will allow users to reset their password by getting an email now if we have an account then we can login so I'll say Corre EMS here is the username I created and I'll login with my password and now that we're logged in we have a few different options up here at the top so we can view our profile and update our profile information now we can also update the profile picture that we have here so if I go to choose file and choose a different file and update that then we can see that profile picture was updated now that's also resized in the background to save room on our web server if that picture is too large so if we go back to our home page then we can view other people's posts so we can view an individual post here by someone else now if we view an individual post that is something that we've written then we also have the ability to update or delete that post so if I go to update and say my latest updated post and post that then we can see that now that post was updated with that new content so we also have the ability to delete posts if I click on delete then we'll ask if we want to confirm that we want to delete the post so I'll say yes and then back on the home page we can see that that post was deleted so that's a quick tour of the application that we're going to be building and building something like this is a great way to learn the ins and outs of a framework because you're going to be exposed to so many different things so for example we'll learn how to work with databases and also how to create an authentication system and accept user input from forms and send email to reset passwords and all kinds of different things like that now since this is a django application we also have the ability to access an admin page if we have the correct permissions and within here you get a nice GUI to be able to view all of this back-end information and update it on the fly if you'd like so let me go back to the main site here so we're going to be learning how to add a lot of functionality to an application within this series now I'm gonna mention this several times throughout the series but if you're following along and would like to download the source code of each step in the process then I will have links to the source code of each video in the description section below so that you can download those if you'd like and also if you'd like to know how to build the same application and another framework then I also have a flash series where I've created the same application using the flask framework so if you're interested in that then I'll put a link to that in the description section below as well also I'll be doing a video in the near future where I compare the two frameworks and when it might be best to use one over the other okay so let's get started with learning how to build this application using Django so I'm going to close down my browser here and pull up my terminal and if you're on Windows you can pull up your command line so first off let's start off by installing the packages that we need to get started out so you can do this in a virtual environment or in your default Python environment but it's always a good idea to separate different projects into their own virtual environments now I'm mainly going to focus on Django in this series so if you need to install Python or want to learn how to work with virtual environments or are wondering how I set up my text editor or anything like that then I'm gonna put links to those videos in the description section below but I'm not gonna go into those and detail in this series I'm just going to assume that you're specifically ready to start learning Django okay so with that said let's get started so first let's install Django so to do this we can simply do a pip install so I'll say pip install Django and we can see it looks like it's successfully installed Django 2.1 but to be sure let's run a command and that command is python - m django - - version and that should display the version of django that we are using so if that runs then django was installed correctly now you can also see that we're using django version 2.1 in this series so be sure that you're also using Django to point 1 or higher or else some of what you learned here might not work in previous versions now I'm also using Python 3.7 so you'll want to use a later version of Python also if you can there are some features that I'll be using in this series such as f strings that are only available if you're running Python 3 point 6 or higher ok so now we have Django installed so now let's create a new project from scratch so I'm on my desktop here you can create this project anywhere you'd like on your machine but I'm going to use my desktop so to create a new project we're going to use some commands that are available to us now that Django is installed and one of these commands is Django admin so if you type that in then it should show you the available subcommands so if I run that that is Django - admin then we can see that we get a list of subcommands here and we can see that there are a lot of different sub commands listed here and we'll see a couple of these later in the video but we're going to use the one right now called start project which is right here so start project will create a new Django project for us that has a complete structure with different files and everything else that we'll need to get started so let's do that so I'm simply I'll clear my screen here and I'm simply gonna say Django - admin start project and now we can specify the name of our project so I'm just gonna call mine Django let's do Django - project and run that ok so that's not a valid project name let's see if I use an underscore instead ok so that worked I always forget which one is which so you can create a project with an underscore but not a dash so I created a new project called Django underscore project and now that we've created that if I look at my desktop then we can see that now I have a directory on here called Django underscore project ok so first let's simply CD into this directory and look at the project structure of what that start project command just created for us so within my command line here I'm gonna say CD into Django underscore project and now I'm just going to open this project and a text editor now I'm using sublime text but you can use any editor that you'd like I have a video on how I set up my editor and that will be in the description and below if anyone is interested so I'm going to open up sublime text here and then drag our Django project into sublime text and open that up so now let's look at the project structure that that start project command created for us now I don't know how to make the text over here in the sidebar of sublime text any bigger so instead I'm gonna use my terminal to look at this so let me open the terminal back up here and clear the screen now on my machine I have a command called tree that helps visualize this a little bit better so I'm going to use that now you might not have this command installed on your machine but you could simply use your editor to view this structure instead so I'm gonna use that tree command okay so we can see that we have a pretty simple structure here now I'm going to open up my editor and go through each of these really quick so just so we can still see the terminal and the structure here I'm going to put this over here on the side about right there and my editor I'm going to drag over here and make this take up about 3/4 of the screen here okay so we can see here in the structure that on the base level we have a manage pie file and a django project directory and that man is not pi file is a file that allows us to run command line commands so let me open that up here in my editor and this is what that manage dot pi file looks like now we'll see this in action in just a second when we run this default site but we won't actually be making any changes to this file so also in our base directory for our project we also have a directory called django project which is also the name that we used for our project itself and within that directory let me open that so within this directory we can see that we have four different files the first is this double underscore Anette dot pi and if we look at that in our text editor then we can see that that is just an empty file so that just tells python that this is a Python package so next we have this settings dot PI file so if I open that in the editor as you can probably tell from the name this is where we'll change different settings and configurations so we'll be using this throughout the series we can see that most of these files have good documentation and links provided where we can learn more information now if we get glanced through here then we can see up here towards the top that we have a secret key and that just adds a lot of security enhancements to Django now we can see that we also have debug set to true here we have an installed app section we have some database settings here and all kinds of different useful settings that we will talk about more in future videos but for now we're just taking a quick glance so looking back at our project structure we also have this URL spy file so let me open that up now this is where we'll set up the mapping from certain URLs to where we sent the user so for example there is one path pattern here set up right now and that is for admin so if we were to go to our site and go to the route admin then it will send us to this admin dot sites not URLs and we'll see more about this in just a moment when we add some additional routes okay lastly we can see that we have this whiskey dot pie file here if I open this up in the editor so whiskey or WSGI is how our Python web application and the web server communicate so Django set up a simple default whiskey configuration for us in this file but we're not going to be actually touching this file okay so that is a quick overview of the project structure that was created for us when we ran that start project command so now let's actually open up the default web site in our browser unlike a framework like flask we actually don't have to write a single line of code to open up a basic web web site in our browser we just have to run a command so to do that we're just going to use that manage py file so to run our server that to access our site we're just going to go over to our terminal and I'll make this larger again so that we can see everything and now within that Django project in the same directory where that manage py file is we can say Python manage py run server and that is a command that we're going to be using a lot okay so you're likely going to see this warning here that says that you have 15 unapplied migrations and then it tells you a command that you can run to get rid of that warning so let's not do that right now I'll explain this migration stuff in just a bit but for now if we look here at the bottom it says that our website is now running and that we can access our site by going to this URL here HTTP 127 0 to 0.1 port 8000 now another name for 127 0 dot 0 dot 1 is localhost it's basically just our local computer that we're currently on now this is actually a running webserver so we have to leave this running while you're viewing your site in the browser or else you won't be able to see it so let's copy and paste this URL that it gives us and open this up in the browser so I'm going to open a new incognito window here and paste that in to our URL bar and we can see that we have what looks to be a website here so this is the default website that Django has created for us and in this series we will modify this so that we have the web application that I showed at the beginning of the video so by default it shows us that a page that says that debug is equal to true and also it provides us some links down here to the Django documentation and stuff like that now when I said that 127 zero to 0.1 was the IP address of our local machine I also mentioned that there's an alias for that IP address called localhost and I like using that more than the IP address itself so if I replace that 127 does zero to 0.1 with localhost then this should still work so now we're at localhost port 8000 and we still have that same site ok so if you remember I said that within our projects URLs dot PI module that we had that admin route so let's try to navigate to that route really quick so if I go to Ford slash admin then we can see that there's actually something on this page we get a login screen so let's pull back up the project and open that URLs dot PI module one more time here so like I said before this is a way to map URLs to certain locations so that they can be handled in a certain way so in this case when we went to ford slash admin then it's going to admin site stat URLs and then the logic within that location handles the route further and we'll look at adding more routes but for now that is how that admin route is working so the logic at this admin dot site URLs that is what allows this admin page here to work correctly now we can't access this with any credentials just yet because there is some more that we need to do first but I just wanted to show you that the URLs and that URLs module are already routing us to different locations and in the next video we'll see how to add some more routes to that module so that we can show users exactly what we want them to see when navigating to different areas of the site but for now let's open our terminal back up and stop running our server so I will pull up my terminal and you can stop running your server by hitting ctrl C and sometimes I have to hit that twice to get that to stop for some reason but just hit ctrl C a couple of times and it should stop now I will clear our page now with that server running and debug mode like it was it should automatically reload any changes that we make to our code but if you ever have any trouble with the website not reloading for any reason then you might want to stop the server just like we did and restart it by running the command that we reran earlier so to bring it back up we can just do python manage py run server and that runs the server again ok so I think that's going to do it for this video in this video we learned how to get Django installed and how to create a new project we also looked at the structure of what gets created and how to pull up that default site in the browser so in the next video we'll learn how to create an application for our site and set up some basic routes now that might sound confusing right now that we'll be creating an application within our current project but we'll see what that means in the next video but if you have any questions about what we covered in this video then feel free to ask in the comment section below and I'll do my best to answer those and if you enjoy these tutorials and would like to support them then there are several ways you can do that the easiest ways to simply like the video and give it a thumbs up and also it's a huge help to share these videos with anyone who you think would find them useful and if you have the means you can contribute through patreon and there's a link to that page and in description section below be sure to subscribe for future videos and thank you all for watching you you

Original Description

In this Python Django Tutorial, we will be learning how to get started using the Django framework. We will install the necessary packages and get a basic application running in our browser. Let's get started... The code for this series can be found at: https://github.com/CoreyMSchafer/code_snippets/tree/master/Django_Blog Flask Tutorials to create this same application: https://www.youtube.com/playlist?list=PL-osiE80TeTs4UjLw5MM6OjgkjFeUxCYH Python Installation: https://youtu.be/YYXdXT2l-Gg Virtual Environment Setup: https://youtu.be/N5vscPTWKOk https://youtu.be/cY2NXB_Tqq0 Sublime Text Setup: https://youtu.be/xFciV6Ew5r4 ✅ Support My Channel Through Patreon: https://www.patreon.com/coreyms ✅ Become a Channel Member: https://www.youtube.com/channel/UCCezIgC97PvUuR4_gbFUs5g/join ✅ One-Time Contribution Through PayPal: https://goo.gl/649HFY ✅ Cryptocurrency Donations: Bitcoin Wallet - 3MPH8oY2EAgbLVy7RBMinwcBntggi7qeG3 Ethereum Wallet - 0x151649418616068fB46C3598083817101d3bCD33 Litecoin Wallet - MPvEBY5fxGkmPQgocfJbxP6EmTo5UUXMot ✅ Corey's Public Amazon Wishlist http://a.co/inIyro1 ✅ Equipment I Use and Books I Recommend: https://www.amazon.com/shop/coreyschafer ▶️ You Can Find Me On: My Website - http://coreyms.com/ My Second Channel - https://www.youtube.com/c/coreymschafer Facebook - https://www.facebook.com/CoreyMSchafer Twitter - https://twitter.com/CoreyMSchafer Instagram - https://www.instagram.com/coreymschafer/ #Python #Django
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from Corey Schafer · Corey Schafer · 0 of 60

← Previous Next →
1 Web fonts using CSS Font Face
Web fonts using CSS Font Face
Corey Schafer
2 Using Font Awesome in Desktop Applications (OS X)
Using Font Awesome in Desktop Applications (OS X)
Corey Schafer
3 Sublime Text 2: Setup, Package Control, and Settings
Sublime Text 2: Setup, Package Control, and Settings
Corey Schafer
4 ArcGIS API for JavaScript Part 1: Our First Web Map
ArcGIS API for JavaScript Part 1: Our First Web Map
Corey Schafer
5 Mac Tip: Windows' Snapping Feature on Mac with HyperDock
Mac Tip: Windows' Snapping Feature on Mac with HyperDock
Corey Schafer
6 Linux/Mac Terminal Tutorial: Creating Aliases for Commands
Linux/Mac Terminal Tutorial: Creating Aliases for Commands
Corey Schafer
7 ArcGIS API for JavaScript Part 2: Starting Templates
ArcGIS API for JavaScript Part 2: Starting Templates
Corey Schafer
8 Paver Patio Time Lapse
Paver Patio Time Lapse
Corey Schafer
9 Mac Tip: Ways to perform Screen Capturing and Screenshots
Mac Tip: Ways to perform Screen Capturing and Screenshots
Corey Schafer
10 WordPress Plugins: Imsanity
WordPress Plugins: Imsanity
Corey Schafer
11 WordPress Tips: Test your theme with Theme Unit Test and Monster Widget
WordPress Tips: Test your theme with Theme Unit Test and Monster Widget
Corey Schafer
12 Sublime Text 3: Setup, Package Control, and Settings
Sublime Text 3: Setup, Package Control, and Settings
Corey Schafer
13 Understanding Binary, Hexadecimal, Decimal (Base-10), and more
Understanding Binary, Hexadecimal, Decimal (Base-10), and more
Corey Schafer
14 Mac Tip: Adding Folder Stacks to the Dock
Mac Tip: Adding Folder Stacks to the Dock
Corey Schafer
15 CSS Tips and Tricks: Add External URLs to Print Stylesheets
CSS Tips and Tricks: Add External URLs to Print Stylesheets
Corey Schafer
16 JavaScript Arrays: Properties, Methods, and Manipulation (Part 7 of 7)
JavaScript Arrays: Properties, Methods, and Manipulation (Part 7 of 7)
Corey Schafer
17 JavaScript Arrays: Properties, Methods, and Manipulation (Part 1 of 7)
JavaScript Arrays: Properties, Methods, and Manipulation (Part 1 of 7)
Corey Schafer
18 JavaScript Arrays: Properties, Methods, and Manipulation (Part 5 of 7)
JavaScript Arrays: Properties, Methods, and Manipulation (Part 5 of 7)
Corey Schafer
19 JavaScript Arrays: Properties, Methods, and Manipulation (Part 4 of 7)
JavaScript Arrays: Properties, Methods, and Manipulation (Part 4 of 7)
Corey Schafer
20 JavaScript Arrays: Properties, Methods, and Manipulation (Part 3 of 7)
JavaScript Arrays: Properties, Methods, and Manipulation (Part 3 of 7)
Corey Schafer
21 JavaScript Arrays: Properties, Methods, and Manipulation (Part 2 of 7)
JavaScript Arrays: Properties, Methods, and Manipulation (Part 2 of 7)
Corey Schafer
22 JavaScript Arrays: Properties, Methods, and Manipulation (Part 6 of 7)
JavaScript Arrays: Properties, Methods, and Manipulation (Part 6 of 7)
Corey Schafer
23 Python Tutorial: if __name__ == '__main__'
Python Tutorial: if __name__ == '__main__'
Corey Schafer
24 Sublime Text Quick Tip: "Go To Definition" Click Shortcut
Sublime Text Quick Tip: "Go To Definition" Click Shortcut
Corey Schafer
25 How to quickly create favicons for the desktop, Apple/Android devices, tablets, and more
How to quickly create favicons for the desktop, Apple/Android devices, tablets, and more
Corey Schafer
26 Easily Resize Multiple Images Using Picasa
Easily Resize Multiple Images Using Picasa
Corey Schafer
27 Easily Resize Multiple Images Using the Mac Terminal
Easily Resize Multiple Images Using the Mac Terminal
Corey Schafer
28 Python Tutorial: virtualenv and why you should use virtual environments
Python Tutorial: virtualenv and why you should use virtual environments
Corey Schafer
29 Python Tutorial: pip - An in-depth look at the package management system
Python Tutorial: pip - An in-depth look at the package management system
Corey Schafer
30 Git Tutorial: Using the Stash Command
Git Tutorial: Using the Stash Command
Corey Schafer
31 How Software Engineers, Developers, and Designers can volunteer their skills
How Software Engineers, Developers, and Designers can volunteer their skills
Corey Schafer
32 Git Tutorial: Diff and Merge Tools
Git Tutorial: Diff and Merge Tools
Corey Schafer
33 Git Tutorial: Change DiffMerge Font-Size on Mac OSX
Git Tutorial: Change DiffMerge Font-Size on Mac OSX
Corey Schafer
34 Sublime Text Quick Tip: Launch Sublime Text from the Terminal
Sublime Text Quick Tip: Launch Sublime Text from the Terminal
Corey Schafer
35 Python Tutorial: str() vs repr()
Python Tutorial: str() vs repr()
Corey Schafer
36 Programming Terms: DRY (Don't Repeat Yourself)
Programming Terms: DRY (Don't Repeat Yourself)
Corey Schafer
37 Programming Terms: String Interpolation
Programming Terms: String Interpolation
Corey Schafer
38 Programming Terms: Idempotence
Programming Terms: Idempotence
Corey Schafer
39 Python Tutorial: Namedtuple - When and why should you use namedtuples?
Python Tutorial: Namedtuple - When and why should you use namedtuples?
Corey Schafer
40 Programming Terms: Mutable vs Immutable
Programming Terms: Mutable vs Immutable
Corey Schafer
41 Python Tutorial: Else Clauses on Loops
Python Tutorial: Else Clauses on Loops
Corey Schafer
42 Overview of Online Learning Resources
Overview of Online Learning Resources
Corey Schafer
43 Mac OS X Terminal Tutorial: Time-Saving Keyboard Shortcuts
Mac OS X Terminal Tutorial: Time-Saving Keyboard Shortcuts
Corey Schafer
44 Git Tutorial for Beginners: Command-Line Fundamentals
Git Tutorial for Beginners: Command-Line Fundamentals
Corey Schafer
45 Quickest and Easiest Way to Run a Local Web-Server
Quickest and Easiest Way to Run a Local Web-Server
Corey Schafer
46 Python Tutorial: Generators - How to use them and the benefits you receive
Python Tutorial: Generators - How to use them and the benefits you receive
Corey Schafer
47 Python Tutorial: Comprehensions - How they work and why you should be using them
Python Tutorial: Comprehensions - How they work and why you should be using them
Corey Schafer
48 Chrome Quick Tip: Quickly Bookmark Open Tabs for Later Viewing
Chrome Quick Tip: Quickly Bookmark Open Tabs for Later Viewing
Corey Schafer
49 Programming Terms: Combinations and Permutations
Programming Terms: Combinations and Permutations
Corey Schafer
50 Git Tutorial: Difference between "add -A", "add -u", "add .", and "add *"
Git Tutorial: Difference between "add -A", "add -u", "add .", and "add *"
Corey Schafer
51 Preparing for a Python Interview: 10 Things You Should Know
Preparing for a Python Interview: 10 Things You Should Know
Corey Schafer
52 SQL Tutorial for Beginners 1: Installing PostgreSQL and Creating Your First Database
SQL Tutorial for Beginners 1: Installing PostgreSQL and Creating Your First Database
Corey Schafer
53 SQL Tutorial for Beginners 2: Creating Your First Table
SQL Tutorial for Beginners 2: Creating Your First Table
Corey Schafer
54 SQL Tutorial for Beginners 3: INSERT - Adding Records to Your Database
SQL Tutorial for Beginners 3: INSERT - Adding Records to Your Database
Corey Schafer
55 Linux/Mac Terminal Tutorial: Navigating your Filesystem
Linux/Mac Terminal Tutorial: Navigating your Filesystem
Corey Schafer
56 Python: Ex Machina Easter Egg - Hidden Message within the Code
Python: Ex Machina Easter Egg - Hidden Message within the Code
Corey Schafer
57 Mac Tip: New Split Screen Feature in El Capitan
Mac Tip: New Split Screen Feature in El Capitan
Corey Schafer
58 Setting up a Python Development Environment in Eclipse
Setting up a Python Development Environment in Eclipse
Corey Schafer
59 Git Tutorial: Fixing Common Mistakes and Undoing Bad Commits
Git Tutorial: Fixing Common Mistakes and Undoing Bad Commits
Corey Schafer
60 SQL Tutorial for Beginners 4: SELECT - Retrieving Records from Your Database
SQL Tutorial for Beginners 4: SELECT - Retrieving Records from Your Database
Corey Schafer

This tutorial series teaches the basics of building a full-featured web application using Django, covering topics such as setting up a new project, creating a basic application, and running the development server. By following along, viewers can gain hands-on experience with Django and learn how to build their own web applications.

Key Takeaways
  1. Create a new Django project using Django-admin startproject
  2. Install Django using pip install
  3. Navigate to the project directory using the CD command
  4. Open the project in Sublime Text
  5. Run the command 'python manage.py runserver' to start the development server
  6. Access the website by going to http://127.0.0.1:8000 or http://localhost:8000
  7. Stop the development server by hitting Ctrl+C
💡 Django provides a robust framework for building full-featured web applications, including a built-in development server and admin interface.

Related AI Lessons

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