django-templates

Tool for insertion of translation tags in Django template? [duplicate]

北慕城南 提交于 2019-12-08 05:10:01
问题 This question already has answers here : Find untranslated strings in HTML templates (2 answers) Closed 5 years ago . Like many Django devs, today I find myself scouring through templates putting in trans and blocktrans as I internationalise a site. Is there a tool that will help me identify blocks of text that are candidates for translation tags and speed this process up? 回答1: I have tried using "Django Template i18n lint", which I found mentioned in this answer. It does a pretty good job of

Display Django Code from a Django template

馋奶兔 提交于 2019-12-08 04:58:49
问题 I am trying to display Django source code from a Django template. However, I cannot find a tag similar to HTML's pre or xmp. Here's the code Also, I have a block with the same name which springs the error. 回答1: If your view puts the source code in a context variable called source, your template might look like this: <pre> {{ source|escape }} </pre> The escape filter will escape certain characters to make sure the HTML is rendered correctly. If you just want to display hard coded template

Can't load image in my django template

萝らか妹 提交于 2019-12-08 03:54:27
问题 My project folders is : mrdoorbeen manage.py mr_doorbeen setting.py mrdoorbeen migrations templates index.html profile profile.html I want to include a image in my profile.html file. i use {% load staticfiles %} in top of the profile.html and use this code at image source : <img src="{% static "image/example.jpg" %}" alt="cant'load"/> and i make a folder in a mr_doorbeen and call it static and in static folder make a image folder and image i put a example.jpg but it doesn't work . my static

customizing request.user with a proxy model that extends Django User model

ぐ巨炮叔叔 提交于 2019-12-08 03:00:37
问题 class MyUser(User): class Meta: proxy = True def do_something: ... With the above, I extend the behavior of the Django User Model using the proxy model technique. I was hoping that I could somehow customize request.user , so that MyUser instance, instead of User instance, is assigned to it every time. How could I implement that, if possible? 回答1: You can inherit a new middleware class from AuthMiddleware or create a separate middleware which will process request after django's auth and change

When to use context processor

本秂侑毒 提交于 2019-12-08 02:41:52
问题 I have a site on which I'm including a userBox with some data shown for each logged user (your name, avatar etc). From what I already know about django it seems obvious, that I should add query for user to context processor (so that I can use {{user}} variable in this included userBox ). But while using django-lfs shop I've noticed, that it's templates are using {{ user }} variable which is nowhere added to context processors nor template tags. Is there any other way to obtain user in my

Generating a unique list of Django-Taggit Tags in Wagtail;

拥有回忆 提交于 2019-12-08 02:41:19
问题 I am trying to add a list of category tags in the sidebar of my Wagtail blog index page. The code below does work, but unfortunately it iterates through the posts and lists all the tags as individual tags, which I ultimately end up with duplicate tags. I built my blog from the Wagtail demo and since it doesn't use Views like I am used to, I am not sure where to add .distinct('tags'). Template {% for b in blogs %} {% for tag in b.tags.all %} <li><a href="{% pageurl b.blog_index %}?tag={{ tag }

Django: How to include a view from within a template

主宰稳场 提交于 2019-12-08 02:13:39
问题 I'm new to django and I was wondering what is the best/recommend approach to include a view (with certain logic, and its resulting HTML) from within a template. My concrete example is as follows: I have a model which is: class City(models.Model): name = models.CharField(max_length=200) class Place(models.Model): city = models.ForeignKey(City) name = models.CharField(max_length=200) state = models.IntegerField() So I need a view to show each city and it's places. Each place should be rendered

How to start forming a django website and how django structures pages?

早过忘川 提交于 2019-12-08 02:09:31
问题 I started a django project for my personal website to learn django. So far I've got my development environment set with everything I need and followed this great tutorial to create some basic data structures and templates. Now I would like to start using my html layout I made before and start implementing the functionalities to it. However I'm having hard time understanding how to accomplish this. I've mostly done java portal solutions before this where I could start the server, create some

django: how to pass css to form.as_ul

我怕爱的太早我们不能终老 提交于 2019-12-08 01:59:53
问题 my form is class Form(forms.Form): ability = forms.ChoiceField(widget= forms.CheckboxSelectMultiple(), choices = SKILLS, required=False) i am displaying it as {{ Form.as_ul }} how do i pass a css ul class to this? Can i do it somewhere in the template? not sure how this works 回答1: Unfortunately you have to create a new widget, but you can use the __init__ and render functions of the existing CheckboxSelectMultiple widget. Add a new ul_attrs parameter to the contructor. from django import

Django email message as HTML

廉价感情. 提交于 2019-12-08 01:38:30
问题 I have an email template that I use to send emails of different kinds. I'd rather not keep multiple email HTML templates, so the best way to handle this is to customize the message contents. Like so: def email_form(request): html_message = loader.render_to_string( 'register/email-template.html', { 'hero': 'email_hero.png', 'message': 'We\'ll be contacting you shortly! If you have any questions, you can contact us at <a href="#">meow@something.com</a>', 'from_email': 'lala@lala.com', } ) email