Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6654823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:26:11+00:00 2026-05-26T01:26:11+00:00

urls.py url(r’^/mailing/(?P<pk>\d+)/preview/$’, PreView.as_view(), name=preview), models.py class Message(models.Model): # … other fields … body =

  • 0

urls.py

url(r'^/mailing/(?P<pk>\d+)/preview/$', PreView.as_view(), name="preview"),

models.py

class Message(models.Model):
    # ... other fields ...
    body = models.TextField(_("Body"), help_text=_("You can use Django <a target='_blank' href='https://docs.djangoproject.com/en/dev/ref/templates/builtins/'>template tags</a>"))

views.py

class PreView(TemplateView):
    template_name = "mailing/preview.html"

    def get_context_data(self, pk, **kwargs):
        try:
            return {"message": Message.objects.get(id=pk)}
        except Message.DoestNotExist:
            raise Http404

template/mailing/preview.html

<div id="body">{{ message.body|safe }}</div>

however django templatetags are not interpreted, only rendered as a string.
I would like to use a

{% now "Y-m-d" %}

tag in message body. In future there will be need to use any other tag.

I have managed two working approaches, both of them are not satisfying me.

  • Use regexps and substitutions,
  • Put whole template source in db TextField (insted of file), and renders a page(template) from it.

I am also thinking about creating templatetag which returns a rendered template out of Message.body. However I am not quite sure whether it will be good or wrong.

Do you have any suggestions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T01:26:11+00:00Added an answer on May 26, 2026 at 1:26 am

    You must use Django template system

    from django.template.loader import get_template_from_string
    from django.template.context import Context
    
    return {"message": message, "body": get_template_from_string(message.body).render(Context())}
    

    EDIT:

    Alternative (and prettier) solution can be custom template filter:

    from django import template
    from django.template.defaultfilters import stringfilter
    
    register = template.Library()
    
    @register.filter
    @stringfilter
    def render(value):
        return get_template_from_string(value).render(Context())
    

    and use:

    {{message.body|render}}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

urls.py: url(r'^book/(?P<booktitle>[\w\._-]+)/(?P<bookeditor>[\w\._-]+)/(?P<bookpages>[\w\._-]+)/(?P<bookid>[\d\._-]+)/$', 'book.views.book', name=book), views.py: def book(request, booktitle, bookeditor, bookpages, bookid, template_name=book.html): book =
urls.py url(r'^some/page/$', views.some_page, {'template_name': 'some/page.html'}, name='some_page'), views.py url = request.build_absolute_uri(reverse('some_page')).lower() response = HttpResponseRedirect(url) return
Just having some problems redirecting urls. urls.py url(r'^index\.asp$', views.Redirect, name='redirect'), views.py pageID = {
In project.urls: url(r'^category/', include('category.urls')), In project/category/category.urls (patterns prefixed with 'project.category.views'): url(r'^list/', 'category_list', name='category_list_name'), In
models: class Band(models.Model): B_Name = models.CharField(max_length=30, primary_key=True) Country = models.CharField(max_length=30) genre = models.ForeignKey(Genre) imageband
I have first: select url from urls where site = '$value' order by url
How do I configure the app.yaml file to redirect all URLs to another URL?
I use url rewriting and one of my urls is /blah/file ILLEGAL CHARS.jpg ILLEGAL
Given a list of urls, I would like to check that each url: Returns
I've got two Urls. A server and a relative url that I would like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.