How to Run django in VS Code

Hello Programmers,welcome to new article of ozanecare. this article i’ll explain all important steps to run django programs inside visual studio code. visual studio code is the free open
source editor for many programming language. let’s see important steps to run python in vs code.

Step 1. Install any python software but i highly recommend you should use 3.7 version of python. open visual studio code. File –> Open Folder –> Select Folder. Next Steps. Add new file in folder and give extension py.
Step 2. Move to Extension . Search and install two packages. a. Python b.Code Runner
. see below image.

Step 3.Write any python program. For Running. click Run–>Start Debugging –> click Python File.
so now, python codes working correctly. see below image.

Step 4 : open command prompt. install djago and requirement.txt
a. pip install django b. pip install -r requirements.txt
Step 5 : for running codes go View –> command palette –> python interpreter select python version. run below codes.
import django

Step 6 : click on Terminal Tab and open new terminal and add new sub-directory. “django-admin startproject Subdirectory_Name” . now you can see file created. Create new python file. Let’s Say views copy and paste below codes.
from django.http import HttpResponse
def index(request):
return HttpResponse(‘Hello, World!’) in terminal run python runserver. see below image.

Step 7 :open file remove all contents and paste below codes. in terminal re-run python runserver . see below image.

from django.contrib import admin
from django.urls import path
# imported views
from Project Name import views
urlpatterns = [
    # configured the url
    path('',views.index, name="homepage")

see upper codes in below picture

Happy Coding…Thanks.

Post Author: adama