- Download Python, and install like a software.
- Download “Visual Studio Code” text editor, and install it.
- Open Command terminal (window+r, type cmd and press enter).
- type py –version this will show your python version
Website in python
Now we will install django, django is a web framework like CodeIgniter in PHP.
- Go to Terminal ant type1python -m pip install django
this will install django on your system
Set Up a Django Project
After you’ve successfully installed Django, you’re ready to create the scaffolding for your new web application. The Django framework distinguishes between projects and apps:
- A Django project is a high-level unit of organization that contains logic that governs your whole web application. Each project can contain multiple apps.
- A Django app is a lower-level unit of your web application. You can have zero to many apps in a project, and you’ll usually have at least one app. You’ll learn more about apps in the next section.
With your virtual environment set up and activated and Django installed, you can now create a project:
1 2 | <span class="gp gp-VirtualEnv">(env)</span> <span class="gp">$ </span>django-admin startproject <project-name> |
This tutorial uses setup
as an example for the project name:
1 2 | <span class="gp gp-VirtualEnv">(env)</span> <span class="gp">$ </span>django-admin startproject setup |
Running this command creates a default folder structure, which includes some Python files and your management app that has the same name as your project:
1 2 3 4 5 6 7 8 9 10 11 | setup/ │ ├── setup/ │ ├── __init__.py │ ├── asgi.py │ ├── settings.py │ ├── urls.py │ └── wsgi.py │ └── manage.py |
In the code block above, you can see the folder structure that the startproject
command created for you:
setup/
is your top-level project folder.setup/setup/
is your lower-level folder that represents your management app.manage.py
is a Python file that serves as the command center of your project. It does the same as thedjango-admin
command-line utility.
The nested setup/setup/
folder contains a couple more files that you’ll edit when you work on your web application.
Note: If you want to avoid creating the additional top-level project folder, you can add a dot (.
) at the end of the django-admin startproject
command:
1 2 | <span class="gp gp-VirtualEnv">(env)</span> <span class="gp">$ </span>django-admin startproject <projectname> . |
The dot skips the top-level project folder and creates your management app and the manage.py
file right inside your current working directory. You might encounter this syntax in some online Django tutorials. All it does is create the project scaffolding without an extra top-level project folder.
Take a moment to explore the default project scaffolding that the django-admin
command-line utility created for you. Every project that you’ll make using the startproject
command will have the same structure.
When you’re ready, you can move on to create a Django app as a lower-level unit of your new web application.
Start a Django App
Every project you build with Django can contain multiple Django apps. When you ran the startproject
command in the previous section, you created a management app that you’ll need for every default project that you’ll build. Now, you’ll create a Django app that’ll contain the specific functionality of your web application.
You don’t need to use the django-admin
command-line utility anymore, and you can execute the startapp
command through the manage.py
file instead:
1 2 | <span class="gp gp-VirtualEnv">(env)</span> <span class="gp">$ </span>python manage.py startapp <appname> |
The startapp
command generates a default folder structure for a Django app. This tutorial uses example
as the name for the app:
1 2 | <span class="gp gp-VirtualEnv">(env)</span> <span class="gp">$ </span>python manage.py startapp example |
Remember to replace example
with your app name when you create the Django app for your personal web application.
Note: If you created your project without the dot shortcut mentioned further up, you’ll need to change your working directory into your top-level project folder before running the command shown above.
Once the startapp
command has finished execution, you’ll see that Django has added another folder to your folder structure:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | setup/ │ ├── example/ │ │ │ ├── migrations/ │ │ └── __init__.py │ │ │ ├── __init__.py │ ├── admin.py │ ├── apps.py │ ├── models.py │ ├── tests.py │ └── views.py │ ├── setup/ │ ├── __init__.py │ ├── asgi.py │ ├── settings.py │ ├── urls.py │ └── wsgi.py │ └── manage.py |
The new folder has the name you gave it when running the command. In the case of this tutorial, that’s example/
. You can see that the folder contains a couple of Python files.
This Django app folder is where you’ll spend most of your time when creating your web application. You’ll also need to make some changes in the management app, setup/
, but you’ll build most of your functionality inside the Django app, example/
.
You’ll get to know the generated Python files in more detail when working through a tutorial or building your own project. Here are three notable files that were created in the app folder:
__init__.py
: Python uses this file to declare a folder as a package, which allows Django to use code from different apps to compose the overall functionality of your web application. You probably won’t have to touch this file.models.py
: You’ll declare your app’s models in this file, which allows Django to interface with the database of your web application.views.py
: You’ll write most of the code logic of your app in this file.
At this point, you’ve finished setting up the scaffolding for your Django web application, and you can start implementing your ideas. From here on out, it’s up to you what you want to build to create your own unique project.
Source: https://realpython.com/django-setup/
View django Project in Browser
Go tyo your ‘project’ folder in ‘Visual Studio’ right click on ‘manage.py’ click on ‘open in integrated terminal’ and type python manage.py runserver
this will show you server URL where you can see your django first setup