After too much motivation, now it’s time to get started with Django. To develop your Django-powered site, you first need to install Python on your system. It is highly recommended to install the latest version of Python, and for those people who are using Python2, it is recommended to switch to Python3. You can easily download the latest version from here.
If you are not familiar with Python, then you should need to brush up your basic knowledge of Python from here.
Now after completely installing python on your system, let’s set up the virtual environment(Why?)
A Virtual Environment is a tool to keep the dependencies required by your different projects in separate places, by creating virtual Python environments for them, it keeps your global python site-packages directory clean and manageable.
Settings Up Virtualenv
Virtualenv creates an isolated Python Environment by creating a folder which contains all the Python executables files, and all the necessary Packages that your project would need.
First Install the Virtualenv on your system via pip:-
You can verify your virtualenv version by-
Now let’s create a Virtualenv. Change the directory you want to start your project
Sometimes in Linux system, you need to explicitly mention that you are creating for python3
Here, venv is the name of the folder, you have created (you can change to whatever name you like). This will install setuptools, pip, wheel and all other packages and dependencies your project would need.
Now to begin with your created virtualenv(venv), you need to activate it, change the directory to the venv folder
For Linux/Mac users,
For Windows users,
Notice that (venv) should be written to the current directory in terminal/cmd.If you are done with working with your virtualenv, you can deactivate it.
Now that you have successfully set up your virtualenv, now you need to install the Django package.
You can download Django of the specific version by specifying the version explicitly. But it is recommended to use the latest version of Django.
Check your installed Django version before moving further. If Django is installed, you should see the version of the django you have installed. If it is not installed, it will give an error telling “No module named django”
Creating your first Django project
Django Project is a directory where django keep its settings file, Database, and all the Scripts, you will be working upon.
It will create the mysite directory containing the files/folders as listed below-
You can change the name outer mysite/ name as you want, many of the developers change it to src, because this is the container of your project, and also it is root directory which all your source code within it. What these .py files actually are, let’s see-
manage.py is a command line utility that lets you interact with your Django project, It contains all the necessary commands you would need like starting the server, creating an app, collect static files which will be discussed later.
__init__.py is a blank python file that tells Python that this directory should be considered a Python package.
settings.py is the main configuration of your Django project, that tells you about how the settings work.
urls.py is the URL declaration for your site, i.e., a Table of Content of your Django-powered site.
wsgi.py is an entry-point for WSGI-compatible web servers to serve your project.
The Development server
Now that you have completely setup your Django project let’s verify that it works. Change your directory to outer mysite folder(or src folder), where your manage.py file is kept. Open up terminal/cmd and write-
You will see this following output on your command line
Open up your browser and browse https://127.0.0.1:8000/ or http://localhost:8000/.
comments powered by Disqus