Explore a blog dedicated to a wide spectrum of topics including Django, Python, Machine Learning, Salesforce, Angular, React, Flutter, Svelte, LINUX, and Amazon Web Services.
Django template engine comes as part of django framework and its very easy, extensible and handy to develop complex web applications with simplest efforts. Lets see basics of django template engine.
Basics:
A template is a text document, or a normal Python string, that is marked-up using the Django template language. Template system in Python can be used in the following way:
Facebook Integration in your Website
Using Facebook integration, we can get the user verified email id, general information, friends, pages, groups and you can post on his profile, facebook pages, groups with out user entering a details in a less span of time.
When your model query API don't go well or you want more performance, you can use raw sql queries in django. The Django Object Relational Mapper (ORM) helps bridge the gap between the database and our code Performing raw queries.
Understanding Django Model Formsets in Detail and their Advanced Usage
Silmilar to the regular formsets, django also provide model formset that make it easy to work with django models. Django model formsets provide a way to edit or create multiple model instances within a single form. Model Formsets are created by factory method. The default factory method is modelformset_factory(). It wraps formset factory to model forms.
Basics of Django Messages Framework
In any web application we need to display notification messages to the end user after processing a form or some other types of his requests. To make this messaging system simple, django provided full support to cookie and session based messaging for both anonymous and authenticated users.
This messages framework is capable of storing messages in one request and retrieving those messages in the subsequent request. Every message has a tag based on its priority(info,warning and error).
Understanding 'GenericForeignKey' in Django
In some cases the we might want to store generic model object, rather a particular specific model as 'ForeignKey'. Generic model object means adding a foreign key from one of your own models to ContentType allows your model to effectively tie itself to another model class
Django Custom Management Commands
In Django project, We could manage by executing some commands which could be invoked through the manage.py.
Using Django's Built in Signals and Writing Custom Signals
Django has a beautiful feature of signals which will record all the actions performed on particular model. In the current blog post we’ll learn how to use django’s built in signals and how to create custom signal.
Django has lot of built in signals like pre_save, post_save, pre_delete and post_delete and etc. Now we’ll learn how to use django’s pre_delete signal with a simple example. In the way we use pre_delete in the present blog post we can use other signals also in the same way.
Django Subdomains to do Advanced Things
We always struggle to give users customization's even before they login to the system like abc.micropyramid.com and django don't know how to handle that out of the box.
We can do it by writing simple middle ware. Django Middle ware have access to request and responses, so, we can get hold on to request and pass it on to django views for further process. Here we will add new property to request and can render pages by seeing at the subdomain property.
Django Generic Many to Many Field Implementation
Django application has a GM2MField that combines the features of the standard Django "ManyToManyField" and "GenericForeignKey".