Django Tutorial by w3schools.com
Django Tutorial by w3schools.com
Create Virtual Environment
python -m venv myworld
Windows:
D:\ myworld\Scripts\activate.bat
Unix/MacOS:
$ source myworld/bin/activate$ django-admin --version
(myworld) ... $ python -m pip install Django$ apt-get update
it gives an error message "Permission Denied:"
Then i tried
My First Project (main project then some apps into it like members)
django-admin startproject my_tennis_clubpy manage.py runserver
output will be like
To Create App (in main dir of my_tennis_club)
python manage.py startapp membersmy_tennis_club
manage.pymy_tennis_club/
members/
migrations/
__init__.py
__init__.py
admin.py
apps.py
models.py
tests.py
views.py
Run the Django Project
py manage.py runserverNOTE: You cannot have a web page created with Django without an app
Django Views
my_tennis_club/members/views.py:
from django.shortcuts import render
from django.http import HttpResponse
def members(request):
return HttpResponse("Hello world!")This is a simple example on how to send a response back to the browser.
Django URLs
Create a file named urls.py in the same folder as the views.py file, and type this code in it:
my_tennis_club/members/urls.py:
from django.urls import path
from . import views
urlpatterns = [
path('members/', views.members, name='members'),
]
my_tennis_club/my_tennis_club/urls.py:
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('', include('members.urls')),
path('admin/', admin.site.urls),
]
Comments
Post a Comment