From the course: Learning Django

Create a Django project

From the course: Learning Django

Start my 1-month free trial

Create a Django project

- [Instructor] We're now ready to create our Django project. First, we need to remember where we cloned the project repository from GitHub. For simplicity I have mine on the desktop, but you may have chosen a different folder location. Now I'll open a terminal and navigate to that folder. If you just installed Python and Django in the last video, you may need to close your terminal and open a new one for everything to work correctly. Since my project folder is on the desktop, I'll navigate to the folder using cd, space, slash, Users, with a capital U, and then slash, my username, which is calebsmith, all one word lower case, and then capital D, Desktop. This navigates to the desktop on a Mac, so the path you might use would be different on a PC and you'll have a different username. Now that I'm in the desktop folder, I'll type ls and hit enter. On Windows you would type dir to do the same thing. From this I can see that I have my exercise files folder and my learning Django project folder. I'll now navigate into that project folder using cd space, learning, dash Django, dash, and then the remaining numbers for the course. From here, I'm ready to create the initial set of files for our project using the command that comes from Django that's called Django admin. To create a project we type django-admin, space, startproject, all one word, lowercase, and then the name of our project. The project we're building is called wisdompets because it's for the wisdompets brand. So I'll call the project wisdompets, all one word, lowercase, and now I'll press enter. Now if I type ls, or dir on Windows, and hit enter, I'll see that it created a folder called wisdompets. Now I'll open that folder in my text editor. I'm using Microsoft's Visual Studio Code, but for this course you use whatever text editor you're most comfortable with. To open the folder, I'll go to file, and then open, and then I'll navigate until I find my project folder, and click open. In the file navigator here on the left, I'll open the wisdompets folder that we just created. With our folder open, we can see the files that the script generated. First, there's a file called manage.py. Beside it there's an inner folder called wisdompets that contains five files. These are double underscore init, double underscore, asgi, settings, URLs, and WSGI. Let's take a look at what each of these files does. We use the manage.py file to run various commands for our project. The __init__ file tells Python that this folder contains Python files. You'll also here it pronounced as dunder anit. The wsgi, or wasgi file, and the asgi file, provide hooks for web servers such as Apache or Nginx when Django is running on a live website. The settings file configures Django, and the urls file routes requests based on the URL. While there are five files that the script generated, we generally don't edit some of these very often. And in this course we won't touch them at all. For our course, the important files will be the settings and urls files which we will use to configure Django and to set up how our URL routing works. With these files generated, we're ready to run our project for the first time. In the terminal that I already had open, I'll now navigate into the inner wisdompets folder that we created by typing cd, space, wisdompets. From here, I'll type ls, or dir on Windows, to make sure I'm in the right place. Now, to run our project for the first time, I'll type python3, space, manage.py, space, and then all one word lowercase, runserver. Remember on Windows you'll use python without the 3. This reports that my server is running. For now, we'll ignore the message about applied migrations. Let's open a browser to see the results. In a browser, I'll type local host:8000 and then hit enter. With this screen loaded, we can see the default page that a new Django project generates. From here, our basic project has been generated and we're ready to build it out completely.

Contents