Creating an Website or Webapp in Django Web Framework
Tags: django, python, shriekdj, webdev
Published: 2022-04-19 13:09:30

## Preface

This Post Will Be Part of [HashNode's Writeathon](https://townhall.hashnode.com/the-epic-hashnode-writeathon) and also part of My Django Related Posts.

So there are many ways to write Back-end for an Web App or Website but we can also write an Web App with Python 3 Programming Language and Django Is One of them.

It's an Free and Open-source Project Created by Django Project Foundation.

---

## Creating An Development Environment for running a Django Project

For Running an Django Project We Will Need Some Prerequisites like In Our Operating System We Need Python 3.8 or Above Installed.

### Installing `python-venv`

Mostly the venv module of python is already installed but it's not installed in Most Cases.

So We Can Install the venv module by our system package-manager.

Like Below is for Ubuntu

```bash
sudo apt-get install python-venv
```

And For Windows it Is installed with Python Exe.

### Creating the Virtual Environment

The given below code will create an virtual environment in new directory named `venv`

```bash
# if only python3 is on system
python -m venv venv

# if multiple python versions are installed on system
python3 -m venv venv
```

### Activating the Python Virtual Environment

Given Below is an Chart about how to activate an virtual environment in that Operating System.

| Platform | Shell | Command to activate virtual environment |
|---|---|---|
| POSIX | bash/zsh | `$ source <venv>/bin/activate` |
|| fish | `$ source <venv>/bin/activate.fish` |
|| csh/tcsh | `$ source <venv>/bin/activate.csh` |
|| Power-Shell Core | `$ <venv>/bin/Activate.ps1` |
| Windows | cmd.exe | `C:\> <venv>\Scripts\activate.bat` |
|| Power-Shell | `PS C:\> <venv>\Scripts\Activate.ps1` |

---

## Installing Django

 You Can Simply install Django In your virtual environment by running below any pip command.

```python
python3 -m pip install Django

# or just python
python -m venv pip install Django

# Directly pip or pip3

pip install Django
pip3 install Django
```

It will also install automatically an package named `django-admin` in our virtualenv.

---

## Creating and Starting First Project In Django

Open Your Command Shell with virtual environment and Run Below Command.

### For Creating Project Under New Folder of current folder Named `django_project`

```bash
django-admin startproject django_project
```

This Will Create an Folder Structure Below.

> current_folder/

>> django_project/

>>> django_project/

>>>> \_\_init\_\_.py

>>>> asgi.py

>>>> settings.py

>>>> urls.py

>>>> views.py

>>>> wsgi.py

>>> manage.py

Whenever you create an Django project be aware it rejects the project name with `-` hyphen symbols so use `_` instead.

### For Creating Project Directly under Current Directory

```bash
django-admin startproject django_project .
```
We add an extra argument of path where to create project, here `.` dot symbol is used for current directory of relative path.

It will create an different folder structure like given below.

> current_folder/

>> django_project/

>>> \_\_init\_\_.py

>>> asgi.py

>>> settings.py

>>> urls.py

>>> views.py

>>> wsgi.py

>> manage.py

---

## Running Django Server on Local host

Now we can run our Django project directly with given below command, but be aware this command are for development environment only.

```bash
python manage.py runserver
```

Given command will run server and you just have to open <http://localhost:8000> or <http://127.0.0.1:8000> on your browser.

Given Below is an image of the Django Project Running.

![First time Django Project Running](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0irqfmq2v4vmxlsz5ly0.png)

---

## If any issues occurred check out this posts.

{% post https://dev.to/shriekdj/how-to-create-and-activate-the-virtual-environment-for-python3-project-3g4l %}

{% post https://dev.to/shriekdj/python-venv-or-virtualenv-wont-activate-on-windows-3e2 %}

{% post https://dev.to/shriekdj/django-posts-announcement-2aph %}

***

## Conclusion

If you found this useful then please share this and follow me! Also check out Buy Me A Coffee if you want to support me on a new level!

[![Buy me a coffee](https://cdn.buymeacoffee.com/buttons/default-yellow.png)](https://www.buymeacoffee.com/shriekdj)

Thanks for reading until now.

Bye 👋.