Django

Creating a Danjgo Project

Creating a Danjgo Project

Now that you have successfully installed Django, let’s explore by creating a project. Every app that we create in Django is called a project. To create a project in Django on either Windows or Linux, you need to open a terminal or command prompt on your system and use the code given below:

$ django-admin startproject firstproject

Now, this code will create a folder with the name “firstproject” with the structure as follows:

firstproject/
manage.py
firstproject/
__init__.py
setttings.py
urls.py
wsgi.py

The structure of the project is described below:

  • manage.py: The file is created under Django-admin which is intended for interaction with the project. You can also get a complete list of commands that are accessible by using the command below:
$ python manage.py help
  • “firstproject/” subfolder: This folder contains all important files of the project such as:
    • __init__.py – This file contains the main code of your project written in Python language. 
    • settings.py – The file contains the project settings.
    • ursl.py – In this file, you will find all links to your projects and the functions used to call them. 
    • wsgi.py – This file is used when you want to deploy your project over WSGI. 

Setting up the Project

As we just discussed that the project will be set up in the firstproject/setting.py file and you can use the following settings for your project:

DEBUG = True

The option will let you check if the project is in debug mode or not. The debug mode is useful to get information about the errors in the project. The value ‘True’ for DEBUG option cannot be used for live projects. But the value of DEBUG has to be set to ‘True’ for serving static files to the server. The following settings are to be done in the development mode:

DATABASES = {
‘default’ : {
‘ENGINE’ : ‘django.db.backend.sqlite3’,
‘NAME’ : ‘database.sql’,
‘USER’ : ‘’,
‘PASSWORD’ : ‘’,
‘HOST’ : ‘’,
‘PORT’ : ‘’,
}
}

Django supports a ‘Database’ dictionary where the database can be set. The settings shown above are used for SQLite Engine for setting up the database. 

Now, to check whether the project is working correctly or not, use the following code in your command prompt or terminal:

$ python manage.py runserver

The above code will give the following output:

Validating models…
0 errors found
January 05, 2023 – 01:09:22
Django version 2.2.5, using settings ‘myproject.settings’
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C

 

Top course recommendations for you

    Web Scraping with Python
    1 hrs
    Beginner
    16.3K+ Learners
    4.44  (1040)
    Visual Graphics in C
    2 hrs
    Intermediate
    16.9K+ Learners
    4.5  (846)
    Swift Tutorial
    2 hrs
    Beginner
    3.9K+ Learners
    4.49  (196)
    Systematic Inventive Thinking Innovations
    1 hrs
    Beginner
    2.5K+ Learners
    4.51  (154)
    React JS Tutorial
    2 hrs
    Beginner
    68.1K+ Learners
    4.5  (5123)
    Linux Tutorial
    2 hrs
    Beginner
    55.1K+ Learners
    4.48  (5433)
    Functions in Python
    1 hrs
    Beginner
    17.8K+ Learners
    4.47  (1098)
    GitHub Tutorial for Beginners
    2 hrs
    Beginner
    20.5K+ Learners
    4.44  (1442)
    Trees in Java
    2 hrs
    Beginner
    8.3K+ Learners
    4.53  (233)