This series is specifically for beginners who want to learn the Django. The Web framework based on Python. As you should know, Python is a requirement, and we'd be making use of Python v3.0+. It'd also be nice if you know some HTML and CSS. I'm not saying know it all level. Just basic knowledge.
I'm also learning, so you might have some questions and I might not be able to answer immediately. However, feel free to ask questions, I'd try my best to answer.
So in this lesson, we'd be learning about:
Before starting, you should know a few things:
- The Django Project has great documentation. You should make sure to check it out.
- This tutorial would be done completely on a Linux machine and should work perfectly for Linux distributions and MacOS. You might need to do a little bit of extra work if you're using Windows.
- All commands to be run in the terminal would start with a '$'. The '$' is not part of the command
- Feel free to skip to sections you need if you're already familiar with the previous sections.
Python needs to be installed and as mentioned earlier, Python version 3.0 or greater.
To check if python3 is installed, open your terminal and type
Running that should open a prompt similar to this:
Python 3.7.3 (default, Apr 3 2019, 05:39:12) [GCC 8.3.0] on linux Type "help", "copyright", "credits" or "license" for information. >>>
If it does, you're good to go. If not, you need to first install python3. You can go to the official site to download it and install it. If you're on Linux. You could try:
$ sudo apt install python3
This would install the latest version of Python3.
Pip is basically a package manager for python. To install it, visit the documentation here or try:
$ sudo apt install python3-pip
I would suggest using a virtual environment because it allows you to basically localize your project and all the packages you use while working. To install virtualenv, open your terminal and run:
$ sudo pip3 install virtualenv
$ sudo apt install python3-venv
Now that we have installed virtualenv, lets create one.
$ virtualenv -p python3 myvenv
$ python3 -m venv myvenv
You can replace 'myvenv' with the name of your choice
$ source myvenv/bin/activate
To deactivate it:
at this point, I'm getting tired. Maybe you are too. Go take a short walk🌞. I'd be here when you're back.
No? No walk? Okay. Well, to install django, first ensure that your virtualenv is active. Then run:
$ pip install Django
This would download and install the Django package into your virtual environment.
And that installs all we need to start.
Our project would be named awesome because you're awesome😉 . Feel free to give it another name, but don't forget, anywhere you see awesome, you replace it with your project name. To create, run:
$ django-admin startproject awesome
And! BoOm💥 We have a new project named awesome.
To run a project, first move into the directory of the project.
$ cd awesome
/awesome$ python manage.py runserver
You get something like this:
Watching for file changes with StatReloader Performing system checks... System check identified no issues (0 silenced). You have 17 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions. Run 'python manage.py migrate' to apply them. June 17, 2019 - 17:41:50 Django version 2.2.1, using settings 'awesome.settings' Starting development server at http://127.0.0.1:8000/ Quit the server with CONTROL-C.