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.1K+ Learners
    4.45  (985)
    Visual Graphics in C
    2 hrs
    Intermediate
    16.6K+ Learners
    4.49  (812)
    Swift Tutorial
    2 hrs
    Beginner
    3.9K+ Learners
    4.5  (185)
    Systematic Inventive Thinking Innovations
    1 hrs
    Beginner
    2.5K+ Learners
    4.51  (138)
    React JS Tutorial
    2 hrs
    Beginner
    67K+ Learners
    4.5  (4797)
    Linux Tutorial
    2 hrs
    Beginner
    53.9K+ Learners
    4.48  (4986)
    Functions in Python
    1 hrs
    Beginner
    17.5K+ Learners
    4.47  (1037)
    GitHub Tutorial for Beginners
    2 hrs
    Beginner
    20K+ Learners
    4.43  (1300)
    Trees in Java
    2 hrs
    Beginner
    8.1K+ Learners
    4.52  (187)