What are some requirements to start Django?
Creating a Django project
The procedure described is based on the installation recommended by Django and comes with no frills. You can also use this tutorial to follow my other posts, where I always start with a fully functional Django project (with the exception of some tutorials for beginners). Enough said, let's get started.
Creation of the project
Requirements: Python 3.6 or higher is installed on your computer and you are no stranger to working in a command line such as the terminal in Linux / Mac or PowerShell on Windows.
Note for Windows and Mac users: I developed the tutorial in Linux Mint. The commands in Windows PowerShell are sometimes different. In these cases both commands are listed. In principle, the same commands apply to macOS as to Linux, where not both commands are also listed.
First we install the latest stable version of Django in a virtual environment. Think about the name for your new project. It's best to choose a short name for it that describes what the project is doing. In this case we call the project django_start.
Now open the command line and create a directory in your documents folder for this tutorial. Type the following:
And change to the new directory:
It is common practice to run the installations for each Python project in its own virtual environment. This means that all the dependencies of a project are isolated in a separate working environment without interfering with one another. I use the tool for working with virtual environments, which is integrated from Python 3.6 onwards. For older versions of Python, I recommend virtualenv, the predecessor of venv. There are definitely other tools, such as pyenv (which is often recommended), but here, too, the following applies to me: Reduce complexity and work that works reliably (pyenv, for example, did not do that for me). Of course, you are free to choose the tool that suits you best. In this tutorial I am using venv.
First create the directory for the virtual environment and name it (or another name that suits you better):
Activate the virtual environment:
Your command line prompt should now be a (env) as the first entry. This signals to you that the virtual environment is active and that you are working with the instance of Python in your virtual environment and not with the main instance of Python. It should look something like this (the important thing is the display (env) at the very beginning of the line):
Mac and Linux:(env) didier @ computer ~ / Documents / django_crud_app $
Windows:(env) PS C: \ Users \ Didier \ Documents \ django_crud_app>
You are now ready to install Django. To do this, type the following command:
This will install the latest version of Django in your virtual environment called (e.g. 3.1.4). To install a specific version, type e.g. for a project with Django 2.2. As soon as the installation has gone through successfully, we create our new Django project, which we simply call:
Your folder structure should look like this:└── env │ └── (...) ├── django_start │ ├── manage.py │ └── django_start │ ├── asgi.py │ ├── __init__.py │ ├── settings.py │ ├── urls.py │ └── wsgi.py
This completes the installation step successfully. Before we start working on our new project, check the installation and start the new project. To do this, switch to the folder
In this folder you will find a command line help module for working with Django. With this file we can start the Django development server, migrate databases, etc. Now start the new Django project. To do this, type:
The output on the command line should look something like this:Watching for file changes with StatReloader Performing system checks ... System check identified no issues (0 silenced). You have 18 unapplied migration (s). Your project may not work properly until you apply the migrations for app (s): admin, auth, content types, sessions. Run 'python manage.py migrate' to apply them. December 20, 2020 - 16:11:21 Django version 3.1.4, using settings 'django_start.settings' Starting development server at http://127.0.0.1:8000/ Quit the server with CONTROL-C.
You will receive a message that there are still open migrations. First end the current process with and display the folder structure:
The folder structure now looks like this:
Django automatically created a SQLite database for us with the name. For production-ready projects, I would recommend using PostgreSQL, but SQLite is usually sufficient for rapid prototype development. We will now apply the migrations shown above. To do this, type:
You should see this output:Operations to perform: Apply all migrations: admin, auth, contenttypes, sessions Running migrations: Applying contenttypes.0001_initial ... OK Applying auth.0001_initial ... OK Applying admin.0001_initial ... OK Applying admin.0002_logentry_remove_auto_add ... OK Applying admin.0003_logentry_add_action_flag_choices ... OK Applying contenttypes.0002_remove_content_type_name ... OK Applying auth.0002_alter_permission_name_max_length ... OK Applying auth.0003_alter_user_email_max_length ... OK Applying auth.0004_alter_user_username Apply_alter_ophts .0006_require_contenttypes_0002 ... OK Applying auth.0007_alter_validators_add_error_messages ... OK Applying auth.0008_alter_user_username_max_length ... OK Applying auth.0009_alter_user_last_name_max_length ... OK. Applying auth.0010_alter_group_name. Applying auth.0010_alter_group_name ength ... OK Applying sessions.0001_initial ... OK
We have now created a database table for the Django standard apps shown above. Start the Django development server again:
The output is shorter this time:Watching for file changes with StatReloader Performing system checks ... System check identified no issues (0 silenced). June 07, 2020 - 15:53:48 Django version 3.0.7, using settings 'django_start.settings' Starting development server at http://127.0.0.1:8000/ Quit the server with CONTROL-C.
Now call up the address with an Internet browser http://127.0.0.1:8000/on. You should now be greeted by the Django rocket, as in the picture below:
Voilà, the Django project is now up and running and you can start developing your new app. I wish you success!
- Why is NaH an ionic bond
- Can we say that time is money
- When was the Large Hadron Collider built
- Arizona is just brown
- When will mobile batteries get better?
- How stressful is studying architecture
- Which cities get Jio fiber optic
- Is DigitalOcean really a cloud provider?
- How can you rename yourself effectively?
- What is 360
- What are schools of English criticism
- What is the botanical history of Nepenthes
- Telangana students can study at Veltech University
- What is app tunneling
- Has anyone worked for InstaCart
- What stocks does Warren Buffett hold now?
- Can antidepressants treat negative symptoms in schizophrenia
- Is the circle game racist
- You can buy Netflix for a year
- Why are perfectionists not good employees
- What should everyone know about drop shipping?
- How did evolution create instinct and conscience?
- What are the upcoming films from Kajol
- Why does the heart have neurons