I have troubles with django allauth
Here's my template
password_reset_key_message.txt
{% autoescape off %}
{% load static from staticfiles %}
{% load i18n %}Hello{% if username %}, {{ username }}{% endif %}!
{% if username %}{% blocktrans %}In case you forgot, your username is {{ username }}.{% endblocktrans %}{% endif %}
You're receiving this e-mail because you or someone else has requested a password for your user account.
It can be safely ignored if you did not request a password reset. Click the link below to reset your password.
{% load static %}
<img src="{% static "avatar.jpg" %}" alt="avatar" />
{{ password_reset_url }}
{% if username %}{% blocktrans %}In case you forgot, your username is {{ username }}.{% endblocktrans %}
{% endif %}{% blocktrans with site_name=current_site.name site_domain=current_site.domain %}Thank you for using {{ site_name }}!
{{ site_domain }}{% endblocktrans %}
{% endautoescape %}
I'm trying to add image in email body (already trying with link on source and converting image to base64) but got same result
But when I click on reset_email I got this result:
Related
I'm trying to reset the password_reset_email.html template in my django app by adding this file in templates/registration/password_reset_email.html:
{% load i18n %}{% autoescape off %}
{% blocktranslate %}You're receiving this email because you requested a password reset for your user account.{% endblocktranslate %}
{% translate "Please go to the following page and choose a new password:" %}
{% block reset_link %}
{{ protocol }}://{{ domain }}{% url 'password_reset_confirm' uidb64=uid token=token %}
{% endblock %}
{% translate 'Your username, in case you’ve forgotten:' %} {{ user.get_username }}
{% translate "Thanks for using our app!" %}
{% blocktranslate %}The team{% endblocktranslate %}
{% endautoescape %}
However it raises a TemplateSyntaxError:
'blocktranslate', expected 'endautoescape'. Did you forget to register
or load this tag?
What am I doing wrong?
I am trying to show a list of user emails in my user profile template, which seems like a really simple thing to do, but I can't get anything to display.
I've tried using {{ email }} in my loop, but it just returns the current users email a bunch of times.
I've also used {{ emailAddress.email }} which doesn't return anything.
My user profile template:
{% extends "base.html" %}
{% block content %}
<title>{% block title %} | {{ username }}{% endblock %}</title>
<h2>{{ username }}</h2>
<p><b>Location: </b>{{ user.profile.location }}</p>
<p><b>Email: </b>{{ email }}</p>
<p>
{% for emailAddress in emailList %}
{{ user.email }}
{% endfor %}
</p>
Edit Profile
{% endblock content %}
My user profile view:
def loggedin(request):
return render_to_response('loggedin.html',
{'username':request.user.username,
'user':request.user, 'email':request.user.email,
'emailList':User.objects.values_list('email', flat=True)})
Something's wrong with your for loop.
{% for emailAddress in emailList %}
{{ user.email }}
{% endfor %}
You are looping through emailList and every element is assigned to a variable emailAddress. Your loop should look like this.
{% for emailAddress in emailList %}
{{ emailAddres }}
{% endfor %}
Note that emailList is already a list of emails so you don't need to do emailList.email.
So, I've visited a lot of questions here on SO regarding Django block tags, but I was unable to learn from them in my perticular problem.
week_table.html
{% load base_extras %}
...
{% for shift in shifts %}
{% if shift.user %}
{% if user in shift.user.all or shift.user.count < shift.usernum %}
<td class="clickable" href="{% url 'termini:shift_add_remove' shift.id %}">{% if shift.name %}{{ shift.name }}<br>{% endif %}{% for usr in shift.user.all %}{% shift_info usr %}{% endfor %}</td>
{% else %}
<td>{% if shift.name %}{{ shift.name }}<br>{% endif %}{% for usr in shift.user.all %}{% shift_info usr %}{% endfor %}</td>
{% endif %}
{% else %}
<td class="clickable" href="{% url 'termini:shift_add_remove' shift.id %}">{{ shift.name|default:"" }}</td>
{% endif %}
{% endfor %}
The problem is I get Invalid block tag: 'shift_info', expected 'empty' ili 'endfor' error
shift_info is defined in base_extras.py
base_extras.py
from django import template
import re
register = template.Library()
#register.simple_tag
def user_info(user):
name = '%s %s' % (user.first_name, user.last_name)
if not name.strip():
name = user.username
return name
It's a simple case of typos and not looking at your own code...
I have made it possible for users on my website to upload a post, and to see all the other posts from other users as well. The below code attaches the user, who wrote the post, userpicture.
I wanted it to be a link to that user. My problem is that the below code links to the current user, and not the user which created the post.
Anyone who has some ideas of how to fix this? Thank you!
{% if item.sender.userpicture_set.all %}
{% for item in item.sender.userpicture_set.all %}
{% if item.active %}
{% if forloop.first %}
{% if forloop.last %}
<a href='/members/{{ user.username }}'><img src='{{ MEDIA_URL }}{{ item.image }}' class='img-responsive' id='post-userpicture'/></a>
{% endif %}
{% endif %}
{% endif %}
{% endfor %}
<small><a href='/members/{{ user.username }}'>{{ item.sender }}</a><span style='color: grey;'> {{ item.sent }}</span></small>
{% endif %}
In your item model, add a field username, which stores the username of the user who made this post.
Here, it creates a link to the current user, because "user" doesn't have any information about the post. It has information about the current user.
After adding the 'username' field,
{% if item.sender.userpicture_set.all %}
{% for item in item.sender.userpicture_set.all %}
{% if item.active %}
{% if forloop.first %}
{% if forloop.last %}
<a href='/members/{{ item.sender.username }}'><img src='{{ MEDIA_URL }}{{ item.image }}' class='img-responsive' id='post-userpicture'/></a>
{% endif %}
{% endif %}
{% endif %}
{% endfor %}
<small><a href='/members/{{ item.sender.username }}'>{{ item.sender }}</a><span style='color: grey;'> {{ item.sent }}</span></small>
{% endif %}
UPDATE:
I have change to item.sender.username. This should work.
The problem is that you are referencing the user object in your link as <a href='/members/{{ user.username }}'>, the correct url should be something like <a href='/members/{{ item.sender.username }}'> but it requires you to have a ForeignKey reference to the user in the item model.
The django contrib comments form i'm using:
{% get_comment_form for post as form %}
<form action="{% comment_form_target %}" method="post">{% csrf_token %}
{% if next %}
<div><input type="hidden" name="next" value="{{ next }}" /></div>
{% endif %}
{% for field in form %}
{% if field.is_hidden %}
<div>{{ field }}</div>
{% else %}
{% if field.name == 'comment' %}
{% if field.errors %}{{ field.errors }}{% endif %}
<p
{% if field.errors %} class="error"{% endif %}
{% ifequal field.name "honeypot" %} style="display:none;"{% endifequal %}>
{{ field.label_tag }} {{ field }}
</p>
{% endif %}
{% endif %}
{% endfor %}
<p class="submit">
<input type="submit" name="post" class="submit-post" value="{% trans "Post" %}" />
</p>
</form>
After submitting the form, it redirects to http://127.0.0.1:8000/comments/posted/?c=..
That means it calls the template django/contrib/comments/templates/comments/posted.html
The content of django/contrib/comments/templates/comments/posted.html:
{% extends "comments/base.html" %}
{% load i18n %}
{% block title %}{% trans "Thanks for commenting" %}.{% endblock %}
{% block content %}
<h1>{% trans "Thank you for your comment" %}.</h1>
{% endblock %}
That doesn't extends my project's base.html.
I need to customize/override that template so that it extends my project's base.html. How can i do that?
If i can't do that, then if i upload my django web project on server, then how would i edit the content of django/contrib/comments/templates/comments/posted.html so that it looks like that:
{% extends "path/to/myproject/templates/base.html" %}
{% load i18n %}
{% block title %}{% trans "Thanks for commenting" %}.{% endblock %}
{% block content %}
<h1>{% trans "Thank you for your comment" %}.</h1>
{% endblock %}
On local pc, for this time i changed/edited the content of django/contrib/comments/templates/comments/posted.html hard-coded to extends my project base.html.
Can anyone give some idea to solve this? I have searched a lot to solve this.
Just override it in your project's "templates" directory:
<project_root>/templates/comments/posted.html
It doesn't seem to be well documented in either the comments app or Django's general template documentation, but it works the same as overriding admin templates (which is documented).