Chapter 4. Create CRUD Web Application

Basic CRUD Structure in Django

Basic CRUD Structure in Django
Tag:

Django framework is well-designed to execute the CRUD concept efficiently. Five key design points exist to build a CRUD-based web application in Django.

1 views.py

views.py is used to build logic to handle HTTP requests dispatched from urls.py. You can build the logic from scratch; however, Django provides pre-made logic templates named generic views. By using generic views, you can build web applications with simple code. To handle each CRUD page, you need to design different views for each page.

2 urls.py

urls.py is used as a URL dispatcher. HTTP requests from a browser are handled by the URL dispatcher first. It dispatches the requests to related views (defined in the views.py file). To handle each CRUD page, you need to define different URL patterns for each page.

3 Templates

Django templates usually consist of multiple HTML files. They are saved under the templates directory, whose path is defined in settings.py. The template HTML files are used to convert data handled by views.py into the HTML format. To handle each CRUD page, you usually need to prepare different HTML files for each page.

4 settings.py

settings.py is used to define general settings for Django applications, such as defining key files or directory paths or registering domains to allow access to the web application.

5 models.py

models.py is used to design a database for the web application. As we already explained in the previous chapter, we don't cover Django models in this chapter; however, the case examples in this chapter use the model designed in the previous chapter.

Django framework is well-designed to execute the CRUD concept efficiently. Five key design points exist to build a CRUD-based web application in Django.

1 views.py

views.py is used to build logic to handle HTTP requests dispatched from urls.py. You can build the logic from scratch; however, Django provides pre-made logic templates named generic views. By using generic views, you can build web applications with simple code. To handle each CRUD page, you need to design different views for each page.

2 urls.py

urls.py is used as a URL dispatcher. HTTP requests from a browser are handled by the URL dispatcher first. It dispatches the requests to related views (defined in the views.py file). To handle each CRUD page, you need to define different URL patterns for each page.

3 Templates

Django templates usually consist of multiple HTML files. They are saved under the templates directory, whose path is defined in settings.py. The template HTML files are used to convert data handled by views.py into the HTML format. To handle each CRUD page, you usually need to prepare different HTML files for each page.

4 settings.py

settings.py is used to define general settings for Django applications, such as defining key files or directory paths or registering domains to allow access to the web application.

5 models.py

models.py is used to design a database for the web application. As we already explained in the previous chapter, we don't cover Django models in this chapter; however, the case examples in this chapter use the model designed in the previous chapter.

Tag: