top of page

How to make python project using Django framework ?

Updated: Mar 18, 2021


In previous Blog we discussed about how to install Django and how to run server. Now in this blog we will discussed about how to make changes in project file so it run properly. For example we will create a simple helloworldApp.


After setting path run these two commands on the cmd:

"path">django-admin startproject DemoApp

and run again this one to create hello world APP

C:\Users\naveenkumar\nawproject\djangorpoject\myproject>python manage.py startapp helloworldApp

And after this

>Python manage.py migrate

After running server:

Open pycharm and open DemoApp folder by selecting option in pycharm as per screenshot.:

file>open>select location and done ok.


When server is started first setup these three file(urls.py, setting.py and view.py) by using some code line(module name helloworldApp(project name))

urls.py:

from django.contrib import admin

from django.urls import path

urlpatterns = [ path('admin/', admin.site.urls),

If your create helloworldApp module than add two code line: from django.contrib import admin from django.urls import path from helloworld.views import View urlpatterns =

[ path('admin/', admin.site.urls), path('helloworldApp/',View)

]

setting.py:

Set app mane in installed Apps

Before adding app name:

INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', ]

After adding app name:

INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'helloworldApp', ]

view.py:

Before adding code line it looks like that:

from django.shortcuts import render

from django.http import HttpResponse

return HttpResponse("Hello")

After adding code line:

from django.shortcuts import render

from django.http import HttpResponse

def View(request):

return HttpResponse("Hello")

Start server by using:

>Python manage.py runserver

and run http://127.0.0.1:8000/app0/ on local browser

Output:hello



For more details contact here or a any help go to the codersarts website
If you like Codersarts blog and looking for Assignment help,Project help, Programming tutors help and suggestion you can send mail at contact@codersarts.com.


bottom of page