Algoteka
Log in to submit your own samples!

Serve a Page from Server

Problem by oml1111
# Tech tags Title Creator Created date
1 0
Django
2022-06-13 23:34
View all samples for this language (1 verified and 0 unverified)

Function view | Python | Django |

By oml1111 |
0 likes

Responds to requests to the url /sample-page with a simple string response.

Prerequisites

Code

example\urls.py

from django.urls import path  
import example.views as views  
  
urlpatterns = [
    ...
    path('sample-page', views.view_sample_page, name='sample_page'),  
]

example\views.py

from django.http import HttpResponse  
  
def view_sample_page(request):  
    return HttpResponse("Welcome to the sample page!")

django_sample\urls.py

from django.urls import include, path  
  
urlpatterns = [  
    ...
    path('', include('example.urls')),  
]

Further reading

Guides/Articles

Writing your first Django app, part 1 - djangoproject.com

References

classes
django.http.HttpResponse docs.djangoproject.com
functions
django.urls.include docs.djangoproject.com
django.urls.path docs.djangoproject.com

Problem Description

In your server back-end software, create a new accessible page (e.g. in /sample-page) that outputs something simple

View sample discussion (0 comments)
View problem discussion (0 comments)