Django Project

Facebooktwitterredditpinterestlinkedinmailby feather

Django Project

Let’s start to use it. Each web app you want to build in Django is called a project; and a project is a collection of apps. A software is a series of MVT-based code files. Let’s say we want to build a website as an example, the website is our project and applications are the form, news, communication engine. This design makes it easier to transfer an application between projects since it is independent of each task.

Create a Project

 where we want our project to be built.

$ django-admin startproject myproject1

This will create a “myproject1” folder with the following structure –

 

The “myproject1” folder is just our project container, it actually contains two elements –

1-manage.py- This file is typical to our local django-admin project to interact with our project via cmd prompt (start server development, sync db …). We can use the code − to get a complete list of commands accessible via manage.py

2- The “myproject1” subfolder − This folder is the actual python package of our project. It contains four files –

    _init_py- This folder is used as a package only for python.

   settings.py- As the name indicates itself, our project settings.

   urls.py- It is where we define the mapping between URLs and views. All links of your project and the function to call.

wsgi.py- To deploy a project over WSGI(The goal is to provide a relatively simple but robust interface that can accommodate all (or most) interactions between a Web server and a Web application.)

 

Setting Up Our Project

Our project is set up in the subfolder myproject1/settings.py. Following are some important options you might need to set before –

Debug=True

This option is uses to set if our project is in debug mode or not. Debug mode collect more information regarding project’s error. It will Never set it to ‘True’ for a live project. However, this has to be set to ‘True’ only if we want the Django light server to serve static files.

Note-Do it only in the development mode.

 

Database is set in the ‘Database’ dictionary. Django is also in support of

  • MySQL (django.db.backends.mysql)
  • PostGreSQL (django.db.backends.postgresql_psycopg2)
  • Oracle (django.db.backends.oracle)
  • MongoDB (django_mongodb_engine)
  • NoSQL DB

Now that your project is created and configured make sure it’s working −

We will get something like this after running  above code –

Facebooktwitterredditpinterestlinkedinmailby feather