Tuesday, April 22, 2025

Django First Html Page

First - create tamplate folder in my_site folder.

Then create home.html page in that template folder. We can just put simple H1 Heading there, or some lorem ipsum for test.

Then, go to views.py and create function that will respond to user request with home.html


from django.shortcuts import render

def home(request):
    return render(request, 'home.html', {})

We will create routing in local urls.py file (in my_site folder):


from django.urls import path
from . import views

urlpatterns = [
    path('', views.home, name='home'),
]

We also need to change global routing file - urls.py, in main my_projects folder.


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

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('my_site.urls'))
]

Then, run server and visit http://127.0.0.1:8000


C:\my_projects>python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).
July 26, 2020 - 11:15:27
Django version 3.0.8, using settings 'my_projects.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
[26/Jul/2020 11:15:29] "GET / HTTP/1.1" 200 25
[26/Jul/2020 11:15:30] "GET / HTTP/1.1" 200 25
[26/Jul/2020 11:15:31] "GET / HTTP/1.1" 200 25
[26/Jul/2020 11:15:31] "GET / HTTP/1.1" 200 25
[26/Jul/2020 11:15:31] "GET / HTTP/1.1" 200 25
[26/Jul/2020 11:15:31] "GET / HTTP/1.1" 200 25

You will be able to see whatever is in home.html

No comments:

Post a Comment

Tkinter Introduction - Top Widget, Method, Button

First, let's make shure that our tkinter module is working ok with simple  for loop that will spawn 5 instances of blank Tk window .  ...