DEV Community

Vishnu S Reddy
Vishnu S Reddy

Posted on

How to create your first Django app on Windows?

Hey, this is just a small article to help you create your first Django app. Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design. Built by experienced developers, it takes care of much of the hassle of Web development, so you can focus on writing your app without needing to reinvent the wheel. It’s free and open source.

Let's get started.

Download and install Python if you don't already have it by clicking here and verify by going to command prompt and type

python --version

Then make sure that pip is installed by typing pip --verison in the terminal.

pip --version

Now install the virtual environment.

pip install virtualenvwrapper-win
mkvirtualenv <name>

Now we install Django

pip install django
django-admin --verison

Now we create a project called prj in a folder called projects

mkdir projects
cd projects

django-admin startproject prj
cd prj

To check the installation type

python manage.py runserver

If everything works fine, you should see this

Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).

You have 17 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.
May 25, 2020 - 00:51:11
Django version 3.0.6, using settings 'prj.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.

Now when you go the link i.e HTTP://127.0.0.1:8000/ on your browser you should see this

Django Home page
Now let's create your app
Go to the terminal and type

python manage.py startapp appname

So now we have created an app called appname.
Let us make this app to print some text like Hello world.
Open your code editor and create a file called urls.py inside appname folder and put int the following code

from django.contrib import admin
from django.urls import path
from . import views
urlpatterns = [
path('',views.home, name="home"),
path('admin/', admin.site.urls),
]

Now go the views.py file and put in the following code:

from django.shortcuts import render
from django.http import HttpResponse

def home(request):
    return HttpResponse("Hello World")

Now in the urls.py file in the project ( Not in the app that we created)

from django.contrib import admin
from django.urls import path, include

urlpatterns = [
path('', include('appname.urls')),
]

Now go to the terminal and run the server by typing

python manage.py runserver

Now go to HTTP://127.0.0.1:8000/ and you should be able to see Hello World.
Congratulations, you have just created your first Django app.
In my next article I will explain about DTL i.e Django Template Language.

Top comments (3)

Collapse
 
coderfromthedead profile image
CoderFromTheDead

Have you published your post on Django Template Language?

Collapse
 
vishnureddys profile image
Vishnu S Reddy

Hey @coderfromthedead ,

No I haven't published it yet. I am working on it. Will publish it within a week.
Do follow me to get notified when I publish it.

Collapse
 
vishnureddys profile image
Vishnu S Reddy

Hey if it helped you, do let me know by giving a <3.