Search Here

How to create Django Project

Now that we have download django and installed setup properly on our computer. Now we are going to create very first django project. The process of creating django project will be same every time when you create new django project.

How to create Django Project

Creating django project

Go ahead and navigate anywhere you want to create django project. I am going to create my first django project on default PycharmProject location, you can create your first django project anywhere you want. Follow these steps to create django project.

  • Open command prompt using administrator where you want to create your django project
  • Type django-admin startproject project_name in command prompt



django-admin startproject MyWebSite       
 


What is django-admin

So this is the tool we got, whenever we download django and installed it. This will allow us to do very cool things during our project phase. 


In project name you can write any name for your convenience for your first django project. But for this tutorial I give name this super generic "MyWebSite" and hit enter.What the django-admin command did this, it create a folder or directory named "MyWebSite" in our given location. 

How to create Django Project

As you can see that our first django project is created now it's time to explore this newly created directory. Before going to explore, I am going to just open this folder in Pycharm IDE. Actually Pycharmis an IDE that JetBrain Company makes. And this is the coolest IDE in the world.
Guys one more thing if you are using pycharm than you can create django project using IDE instead of using django-admin command in command line tool. Steps to create django project using pychar IDE.
  • Open pycharm IDE and click on File>>New Project
  • Give a meaning full name for our project and click on Create button


 How to create Django Project 

So there are two ways to create django project the first one is using command line and the second is by using IDE. You can choose any way to do that.

Explore Django Project Directory


How to create Django Project


Here MyWebSite is just the container where all of the files exist related to django project. It doesn't mean anything to django. The important files are located inside the container (MyWebSite).  

How to create Django Project


Inside the container you can see that we have the same name directory as root directory. If you get little bit confusing than change the name of root directory but don’t change the directory name which is inside the root directory. Beneath the child directory named MyWebSite you can see that there is a file named manage.py.

What is manage.py in django project

Before talking about this file I give you warning:
  1. Never edit this file. 
  2. Never try to delete this filee.
  3. Just ignore it
Its program that comes with django and you can do bunch of cool stuff with this file. It allows you do things like access database, create users etc. Again!!!! This is the file which we never change or touch.
Now you guys thinking that where the file where we work is. So these files are located in child directory named MyWebSite. So go ahead and talk about such files.

How to create Django Project



Init.py


How to create Django Project


The first one is init.py. This file tells that view the child directory MyWebSite as a python package. Actually there is nothing inside this file because we have not code there anything. Again this files tells that treat this directory (MyWebSite) as a python package not a normal directory.

Setting.py

 
How to create Django Project


This file is just the setting in configuration option of you website. So it owns overall settings of your entire website.

Urls.py

How to create Django Project

Now the next one is urls.py. These are the url declarations, in other words it's kind of table of content for your webistes. Let me explain that whenever you go to a website you type the website name for example website_name/about/ or website_name/home/ etc, so this part (/about/ and /home/) of url tell my website how to behave or what to do when this url called. Some times when you go to the url like logout from any site than it just actually perform some functionality and just logout the user and doesn't give you the web page.

Wsgi.py

The next one is wsgi.py. This is the web server gateway interface. It is the special type of web server. We learnt about this file a lot later. Don’t worry about right now.
That's the basic introduction of core django project. Every single website in django is composed of above files. So remember that's not enough its just starting overview. Whenever you installed django and setup the django project like we have did, it actually comes with a web server, that you can use for development. So if you want to check out what our websites looks like that we have created follow these steps.

How to run first django project


  • Open command prompt and navigate to the directory where you have created your django project

  • Type dir

    How to create Django Project



Make sure you see your project name and manage.py. Now we are going to use manage.py to open or boot our web server. In order to do this type

Python manage.py runserver

How to create Django Project


Just open above url on your web browser you see below screen right there.


How to create Django Project

If you see above screen its mean that you have created your very first django website.

Post a Comment

0 Comments