Thursday, July 8, 2021

Django - create your first project and runservers and urls and views

Create a project:
Open your pycharm and create  a project with proper name like djangoCodeSource using system interpreter.

Start the project:
Go to pycharm terminal and cd to the project path and run the following cmd.

django-admin
django-admin startproject myFirstSite

now the folder structure will look like as below:



Runserver:
Python manage.py runserver

C:\Users\Srinanda\Desktop\python\djangoCodeSource\myFirstSite>python manage.py runserver
Django version 3.2.5, using settings 'myFirstSite.settings'
Starting development server at http://127.0.0.1:8000/




Create views:
On your project create a python file views.py and create the code:

from django.http import HttpResponse
def index(request):
    Return HttpResponse("hello")




urls.py:

from . import views

urlpatterns=[
path('admins/', admin.site.urls)
path('',views.index, name='index')
path('about/',views.about, name='about')

]






No comments:

Post a Comment

Featured Post

11g to 12c OSB projects migration points

1. Export 11g OSB code and import in 12c Jdeveloper. Steps to import OSB project in Jdeveloper:   File⇾Import⇾Service Bus Resources⇾ Se...