Getting Started With Django


Once you have installed django on your machine, you are ready to get started. In django - Every web app you want to create is called a project; - A project is a sum of applications. An application is a set of code files relying on the MVT pattern. As example let's say we want to build a website, the website is our project and, the forum, news, contact engine are applications. This structure makes it easier to move an application between projects since every application is independent. ```bash $django-admin startproject project $cd project project$ tree . ├── manage.py └── project ├── asgi.py ├── __init__.py ├── settings.py ├── urls.py └── wsgi.py 1 directory, 6 file ``` ## Project Structure - `manage.py` − This file is kind of your project local django-admin for interacting with your project via command line (start the development server, sync db...). To get a full list of command accessible via manage.py you can use the code - *“project”* subfolder This folder is the actual python package of your project. It contains four files − - `__init__.py` − Just for python, treat this folder as package. - `settings.py` − As the name indicates, your project settings. - `urls.py` − All links of your project and the function to call. A kind of ToC of your project. - `wsgi.py` − If you need to deploy your project over WSGI. ## applications ```bash project$ python3 manage.py startapp app1 project$ tree . ├── app1 │ ├── admin.py │ ├── apps.py │ ├── __init__.py │ ├── migrations │ ├ └── __init__.py │ ├── models.py │ ├── tests.py │ └── views.py ├── manage.py └── project ├── asgi.py ├── __init__.py ├── __pycache__ │ ├── __init__.cpython-36.pyc │ └── settings.cpython-36.pyc ├── settings.py ├── urls.py └── wsgi.py 4 directories, 15 files ``` ## Runing ```bash project$ python3 manage.py runserver 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, contenttypes, sessions. Run 'python manage.py migrate' to apply them. March 27, 2022 - 02:24:18 Django version 3.2.12, using settings 'project.settings' Starting development server at http://127.0.0.1:8000/ Quit the server with CONTROL-C. ``` If you want to run it on any other port ```bash python3 manage.py runserver 9000 ```

This post is written by Pravin

Tags : Django

Share it :      

Leave a comment

captcha