8. Building a lightweight project
The components of Django that we’ve just looked at are really just Python packages that we can import into whichever file structure we wish to create.
The tutor showed us how to create a lightweight site. The idea of this is to replace the helloworld functionality we’ve seen in the last few exercises.
We create a folder called lightweight_site and in it, a file called helloworld.py.
from django.http import HttpResponse from django.conf.urls import url from django.urls import path from django.conf import settings import sys settings.configure( DEBUG=True, SECRET_KEY="ThisIsTheSecretKey", ROOT_URLCONF=__name__, MIDDLEWARE_CLASSES=( 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', ), ) def index(request): return HttpResponse('<html><head></head><body><p>Hello world!</p></body></html>') urlpatterns = [ path('', index) ] if __name__ == "__main__": from django.core.management import execute_from_command_line execute_from_command_line(sys.argv)
Wednesday 20 October 2021, 580 views
Next post: 9. How to start writing a new application in Django Previous post: 7. Django URLs
Advanced Web Development index
- 38. Writing API tests
- 37. Testing in Django
- 36. Class-based views in the Django REST framework
- 35. Building a RESTful web service in Django
- 34. Introduction to CRUD, REST and APIs
- 33. Refactoring with generic views in Django
- 32. Django validators
- 31. Django forms (2) – using the ModelForm class
- 30. Django forms (1)
- 29. JavaScript basics
- 28. Adding CSS to the template
- 27. Django templating
- 26. Deleting and updating records
- 25. Joins, filters and chaining commands
- 24. Using the ORM in views.py
- 23. Adding to the database by writing a script
- 22. Adding to the database with Django Admin
- 21. Migrations
- 20. ORM – work through example
- 19. An introduction to the Object-Relational Mapper
- 18. Altering the database
- 17. SQL functions and summaries
- 16. SQL Query performance
- 15. Queries and table joins in SQL
- 14. Inserts and queries in SQL
- 13. Good practice in relational database design
- 12. Limitations to database modelling
- 11. Building a database using SQL
- 10. Introduction to PostgreSQL
- 9. How to start writing a new application in Django
- 8. Building a lightweight project
- 7. Django URLs
- 6. Django templates
- 5. Django models
- 4. Django views
- 3. Creating a new hello app
- 2. Creating a new virtual environment
- 1. Setting up Django
Leave a Reply