Thursday, December 26, 2024
Google search engine
HomeLanguageslorem – Django Template Tags

lorem – Django Template Tags

A Django template is a text document or a Python string marked-up using the Django template language. Django being a powerful Batteries included framework provides convenience to rendering data in a template. Django templates not only allow passing data from view to template, but also provides some limited features of programming such as variables, for loops, comments, extends, include, lorem etc.
This article revolves about how to use lorem tag in Templates. lorem tag displays random “lorem ipsum” Latin text. This is useful for providing sample data in templates.

Syntax
{% lorem [count] [method] [random] %}

count – A number (or variable) containing the number of paragraphs or words to generate (default is 1).
method – Either w for words, p for HTML paragraphs or b for plain-text paragraph blocks (default is b).
random – The word random, which if given, does not use the common paragraph (“Lorem ipsum dolor sit amet…”) when generating text.

Examples –
  • {% lorem %} will output the common “lorem ipsum” paragraph.
  • {% lorem 3 p %} will output the common “lorem ipsum” paragraph and two random paragraphs each wrapped in HTML

    tags.

  • {% lorem 2 w random %} will output two random Latin words.

lorem – Django template Tags Explanation

Illustration of How to use lorem tag in Django templates using an Example. Consider a project named neveropen having an app named Lazyroar.

Refer to the following articles to check how to create a project and an app in Django.

Now create a view through which we will access the template,
In Lazyroar/views.py,




# import Http Response from django
from django.shortcuts import render
  
# create a function
def Lazyroar_view(request):
  
    # return response
    return render(request, "Lazyroar.html.html")


Create a url path to map to this view. In Lazyroar/urls.py,




from django.urls import path
  
# importing views from views.py
from .views import Lazyroar_view
  
urlpatterns = [
    path('', Lazyroar_view),
]


Now we will create s template to demonstrate lorem tag. Create a base template in Lazyroar.html,




<html>
    {% lorem %}
</html>


Now visit http://127.0.0.1:8000/,

lorem-Django-Template-Tags

Last Updated :
05 Feb, 2020
Like Article
Save Article

<!–

–>

Similar Reads
Related Tutorials
RELATED ARTICLES

Most Popular

Recent Comments