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



When I enter Command
$ 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_club

 py manage.py runserver

 output will be like



To Create App (in main dir of my_tennis_club)

python manage.py startapp members

 my_tennis_club

    manage.py
    my_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 runserver

 NOTE: 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

Popular posts from this blog

PANDAS micro course by www.Kaggle.com https://www.kaggle.com/learn/pandas

Course No 2 Using Python to Interact with the Operating System Rough Notes

Introduction to Git and GitHub https://www.coursera.org/learn/introduction-git-github/