I was able to customize the confirmation email HTML template by adding this file into the templates folder:
templates/account/email/email_confirmation_signup_message.html
Now I'm trying to customize the subject of the email by adding the text I want inside this file:
templates/account/email/email_confirmation_signup_subject.txt
But it doesn't seem to do anything, I still get the default subject all the time.
Does anyone know what I'm doing wrong?
Many thanks!
You have to add this two files...
first:
account/email/email_confirmation_signup_message.html
{% include "account/email/email_confirmation_message.html" %}
second:
account/email/email_confirmation_message.html
The template that you want.
and finally delete the two .txt file:
account/email/email_confirmation_signup_message.txt
account/email/email_confirmation_message.txt
pd: if you copy the folder template/account from your virtual enviroment you have to delete the files over there as well.
Do in this way...
install django-mail-templated
base template file code...
{{ TAG_START_SUBJECT }}
{% autoescape off %}
{% block subject %}
{% endblock %}
{% endautoescape %}
{{ TAG_END_SUBJECT }}
main template file code...
{% block subject %}
Hello User..
{% endblock %}
Change file name to this:-
templates/account/email/email_confirmation_subject.txt
and inside write
{% load i18n %}
{% autoescape off %}
{% blocktrans %}Please Confirm Your E-mail Address or do whatever..{% endblocktrans %}
{% endautoescape %}
Maybe the problem comes with your urls.py file
You need to indicate here the file you use to customize the subject of your email.
PasswordResetView.as_view(template_name='email_confirmation_signup_message.html', subject_template_name='email_confirmation_signup_subject.txt')
For me the default behavior was to have the template in the the project folder and not in the particular apps directory api_project/templates/account/email/email_confirmation_subject.txt!
For anybody that might be here just because [example.com] still appears at the subject even when they customized successfully the templates/account/email/email_confirmation_subject.txt a variable that you need to configure and it's not quit obvious it's ACCOUNT_EMAIL_SUBJECT_PREFIX = '[example.com]'
Related
I've a base.html file which has vertical and horizontal menu-bar:
Wherever I want to use that I just simply write:
{% extends 'base.html' %}
{% block content %}
//html code
{% endblock content %}
But I don't know how to use the same file base.html from templates directory in djando admin.
I want output like this:
What I Tried:
How to override and extend basic Django admin templates?
How do I correctly extend the django admin/base.html template?
Override Navbar in Django base admin page to be same as the base.html
I tried few other solution just don't want to increase the length of question and base.html file's code just has basic bootstrap, html code for menus.
I am new to Django, little explanation would be highly appreciated!
What you are looking is similar to nav-global.
Try this:
First create a folder in your templates folder as admin and create a html file(base_site.html) in the same folder
Assuming you have separate html file for menu-bars(Let's say the file is nav.html).
Write the below code in base_site.html:
{% extends 'admin/base.html' %}
{% block nav-global %}
{% include 'nav.html' %} #Your navigation html file
{% endblock %}
Unrelated to question: I found a git repo which will give you idea how to customize the django-admin menu.
You can just extend the admin's base template as
{% extends "admin/base.html" %}
For example:
{% extends "admin/base.html" %}
{% block sidebar %}
{{ block.super }}
<div>
<h1>Extra links</h1>
My extra link
</div>
{% endblock %}
Also, make sure that you have added the admin app to the INSTALLED_APPS
INSTALLED_APPS = [
# other apps,
'django.contrib.admin',
# other apps,
]
I had the same issue about a year and a half ago and I found a nice template loader on djangosnippets.org that makes this easy. It allows you to extend a template in a specific app, giving you the ability to create your own admin/index.html that extends the admin/index.html template from the admin app. Like this:
{% extends "admin:admin/index.html" %}
{% block sidebar %}
{{block.super}}
<div>
<h1>Extra links</h1>
My extra link
</div>
{% endblock %}
I am trying to set up a proper workflow for a personal website.
I am using the Cactus static site generator which makes use of the Django template system.
I know what I want to do, but I am not sure how to do it as the tutorials for Cactus are limited.
This is what my directory structure looks like:
/mysite/pages/
/mysite/templates/
/mysite/mycontent/
/mysite/plugins/
My template, /mysite/pages/menu.html, looks like this:
<p>Welcome to the page!</p>
{% block body %}
{% endblock %}
And one of my page articles, /mysite/pages/testpage.html, looks like this
{% extends "menu.html" %}
{%block body %}
<p> Test Content </p>
{% endblock %}
But what I am trying to do is set this up so that whatever I want to write for Test Content can be written somewhere else and the copied in to the folder. Something like this:
{% extends "menu.html" %}
{%block body %}
{%include "../mysite/mycontent/TestContent.html}
{% endblock %}
Is this something that Django templates needs to manage? Like I said, I am using Cactus which uses Django templates but I have looked around and am not sure what the standard way of doing this is, even though it seems to work with MVC/MVT philosophy.
There is also an option to use Django plugins with Cactus.
Thanks!
I figured out what I was trying to do. I just had to include the html I wanted using the template language.
{% extends "menu.html" %}
{%block body %}
{% include "./file.html" %}
{% endblock %}
I need to edit the "Add Object" action in the admin. It needs to redirect the user to a custom cause the logic required for adding objects is too complex to be managed in the admin. So, how do I make this possible? i.e:
The picture shows a django-suit admin, but the question is the same. How can I make that button redirect to a custom url? Or, how can I create a similar button that redirects to a custom url (I could disable the default create and leave only the custom button).
Override change_list_template html, the block object-tools-items. It's where add button is placed.
class MyModelAdmin(admin.ModelAdmin):
change_list_template = 'change_list.html'
In your change_list.html
{% extends "admin/change_list.html" %}
{% load i18n admin_static admin_list %}
{% block object-tools-items %}
{% if has_add_permission %}
<li>
<a href="your/custom/url" class="addlink">
{% blocktrans with cl.opts.verbose_name as name %}Add {{ name }}{% endblocktrans %}
</a>
</li>
{% endif %}
{% endblock %}
You need to add your new html in any dir that is included on TEMPLATE_DIRS options. But, you should do it inside your model's app.
-app
-templates
-admin
change_list.html
Add above dir in TEMPLATE DIRS paths.
I'm trying to use this app in my project.
https://github.com/streema/django-favit
I already can use the fav-unfav part of this app. I also want to list favourites of user for every user. In read me part it says use this and it will be listed but I have an error with
{% with user_favorites <user> "baslik.Entry" as favorite_list %}
{% for fav_obj in favorite_list %}
{{ fav_obj }}
{% endfor %}
{% endwith %}
Error:
TemplateSyntaxError at /
u'with' expected at least one variable assignment
This is the template tag part for user_favorites:
#register.assignment_tag
def user_favorites(user, app_model=None):
"""
Usage:
Get all user favorited objects:
{% with user_favorites <user> as favorite_list %}
{% for fav_obj in favorite_list %}
{# do something with fav_obj #}
{% endfor %}
{% endwith %}
or, just favorites from one model:
{% with user_favorites <user> "app_label.model" as favorite_list %}
{% for fav_obj in favorite_list %}
{# do something with fav_obj #}
{%
{% endwith %}
"""
return Favorite.objects.for_user(user, app_model)
How can I get rid of this error? Thanks.
It's a reasonably common convention in documentation that anything in angle brackets is a placeholder to be replaced by the actual value. In this case, <user> is supposed to be replaced by the object containing the actual user.
{% with user_favorites request.user ...
I must say, though, that the documentation still doesn't make any sense. You can't use an assignment tag in a with statement like that - even after correcting the user issue, this still won't work. The confusing thing is that the same syntax is repeated throughout the documentation, but it simply doesn't work.
I think this is simply a bug with the documentation, and suspect that if you simply remove the word "with" this will work.
To use custom template tag in django, it is needed to explicitly load it in template.
Add this line at the beginnig of your template (but after {% extends ... %}, if you have such):
{% load favit_tags %}
Looks like this step is missed from django-favit README.
django trans is not working for me in this case:
{% blocktrans %} {{sign}} {% endblocktrans %}
the {{sign}} are coming from views.py and are Sunsigns like:
'Capricorn'
'Aquarius'
'Pisces'
'Aries'
'Taurus'
'Gemini'
'Cancer'
'Leo'
'Virgo'
'Libra'
'Scorpio'
'Sagittarius'
I added into .po file all their translations and did compilemessages but it is just not translating it. what am I doing wrong?
blocktrans is for translating the text around a variable, but it won't translate the variable itself.
This answer can be helpful for you. More info in docs.
I just did the translation in models.py like this:
_('Capricorn')
_('Aquarius')
_('Pisces')
_('Aries')
_('Taurus')
_('Gemini')
_('Cancer')
_('Leo')
_('Virgo')
_('Libra')
_('Scorpio')
_('Sagittarius')
and in template just
{{sign}}
and it is working.