Skip to main content

How to Create Project in Django Python Framework



Installation and setup of python and Django

Django is a Python framework that is used to make python projects and web applications easily.It works for any python version. It supports a database called SQLite and you don't have to set up the database. For using Django you first need to install python. You can get python @ http://www.python.org.After installing python you can check whether Python is installed or not by typing python command in cmd, and if python is installed you will see the python version in the command line. After that, you can install Django's latest version and start making python projects. For the installation of Django you can refer https://docs.djangoproject.com.Now if you are done with installing python and Django you can check the version of Django you installed by typing and running the command

 python -c "import django;print(django.get_version())"


Creating a project in Django

Change your current directory where you want to store your code in the command line and then run the following command

django-admin.py startproject myproject  

This will create my project directory in your current directory. Remember not to use Django and test as your project name as these are the built-in names of Django and python components and cant be used. Inside your project directory you will see


myproject/
    manage.py
    myproject/
        __init__.py
        settings.py
        urls.py
        wsgi.py


Running up the server 

Now, let's check whether what we have done worked or not. To run the server you need to change it to my project directory and then run the command

python manage.py runserver 

You will get the following output in the command line


Validating models...

0 errors found
April 12, 2013 - 15:50:53
Django version 1.6, using settings 'myproject.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

which means that our Django project is created successfully. Now you can copy-paste this URL in your browser and will see the "Welcome to Django" page. Sometimes it will show an error after you run runserver command and might show errors such as "socket is already in use".That means the port number you are using in URL is already used by some other server. So if you are getting this type of error you need to change your port to 8080. For that run the command: python manage.py runserver 8080.And now use the URL http://127.0.0.1:8080/ in your browser.


Database setup

By default, Django uses the SQLite database. If you are new to the databases you should prefer to use SQLite.SQLite is installed in python so you did need to install anything. Now go to your project directory and inside that open settings.py file and edit the connection settings.

Engine- 'django.db.backends.sqlite3'
Name- Full path to your myproject directory.For example if it is in C drive then enter 'C:/myproject/sqlite3.db'

If you are using SQLite as a database then you can leave the fields username, password, host, port empty. Also, you need to change the Time_zone field to your timezone. You can also see the Installed_apps field in settings.py file where you can see the Django applications which are present by default in the code.


INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    )

Each of these applications requires database tables. So it is necessary to create tables for them before using them. For creating tables run the command

 python manage.py syncdb 

syncdb command will create necessary tables for the applications in installed apps. You will see the messages while creating the tables and you will get a prompt to create a superuser, type yes, and then enter a username, email, and password to create a superuser.

In the next post, I will be writing about how to create models and create views and URLs in Django for creating your first web application.


Comments

Popular posts from this blog

Tricky Questions or Puzzles in C ( Updated for 2026)

Updated for 2026 This article was originally written when C/C++ puzzles were commonly asked in interviews. While such language-specific puzzles are less frequent today, the problem-solving and logical reasoning skills tested here remain highly relevant for modern Software Engineering, Data Engineering, SQL, and system design interviews . Why These Puzzles Still Matter in 2026 Although most Software &   Data Engineering interviews today focus on Programming, SQL, data pipelines, cloud platforms, and system design , interviewers still care deeply about how you think . These puzzles test: Logical reasoning Edge-case handling Understanding of execution flow Ability to reason under pressure The language may change , but the thinking patterns do not . How These Skills Apply to Data Engineering Interviews The same skills tested by C/C++ puzzles appear in modern interviews as: SQL edge cases and NULL handling Data pipeline failure scenarios Incremental vs ...

Program to uncompress a string ie a2b3c4 to aabbbcccc

Below is the program to uncompress a string #include<stdio.h> #include<conio.h> #include<stdlib.h> int main() { char str[100]="a2b3c4d8u7"; for(int i=0;str[i]!='\0';i++) { if(i%2!=0) { for(int j=0;j<atoi(&str[i]);j++) { printf("%c",str[i-1]); } } } getch(); } Want to become a Data Engineer? Check out below blog posts  1.  5 Key Skills Every Data Engineer needs in 2023 2.  How to prepare for Data Engineering Interviews 3.  Top 25 Data Engineer Questions

Programs and Puzzles in technical interviews i faced

I have attended interview of nearly 10 companies in my campus placements and sharing their experiences with you,though i did not got selected in any of the companies but i had great experience facing their interviews and it might help you as well in preparation of interviews.Here are some of the puzzles and programs asked to me in interview in some of the good companies. 1) SAP Labs I attended sap lab online test in my college through campus placements.It had 3 sections,the first one is usual aptitude questions which i would say were little tricky to solve.The second section was Programming test in which you were provided snippet of code and you have to complete the code (See Tricky Code Snippets  ).The code are from different data structures like Binary Tree, AVL Tree etc.Then the third section had questions from Database,OS and Networks.After 2-3 hours we got the result and i was shortlisted for the nest round of interviews scheduled next day.Then the next day we had PPT of t...