That should be all the information needed to fix the problem :)
TL:DR:
use `{{ protocol }}://{{ domain }}{% url
'user_management:password_reset_confirm'
uidb64=uid token=token %}` on line 5 of your email template.
Long answer:
The amount of information you provided last time would have been enough for
my gut feeling, which is the same as the tl;dr. But I needed pretty much
everything you have given here to be sure :)
The traceback is pretty much useless to finding the origin of the error
with template. That's why there is a Template error section. In you case,
as you can guess, django try to find a named url but get nothing. To know
why, we need to dive into the source and the traceback will be our guide.
Starting with the end, the two last function, _reverse_with_prefix and
reverse are internal to django routing. I let them alone.
Next one live in defaulttags and cause issue at a call to reverse. I
believe that it's the url template tag. I'm mainly curious about the
current_app argument in reverse. I know that url name can take the form
"app:name". In your case, that would be
"user_management:password_reset_confirm". The current_app argument come
from the context property of the tag object [1].
When looking at the traceback, two things stand out for the few followings
lines. They all live in the template module and they all have a context
argument. So I skip them.
Next stop is send_mail in contrib/auth/forms.py. We get out of the template
module but we still have the context argument, which disappear in the
following line. Look like a good place to find the value of context.
Oops, look like I was off by one. send_mail take the context argument from
save, same file. The call to send_mail taking 4 lines, the context argument
have been stripped from the line in the traceback. But the context is
defined in the save method [2].
You will notice it's a simple dict without a request key. But if you have
looked at how the URL tag define the current_app, you'll notice it make use
of the request key of the context.
That's the root of your problem. Email are generated without a request. And
without a request, you need to specify the full name of url, as you don't
have access to the current_app. By the way, current_app is matching
app_name you specify in your URL.py file. That's why I asked the full
urls.py the first time.
I hope I'm clear and that will help you :)
All you need to remember is that sometimes, you need to specify the full
name of an url.
[1]
https://github.com/django/django/blob/1.10.5/django/template/defaulttags.py#L428-L434
[2]
https://github.com/django/django/blob/1.10.5/django/contrib/auth/forms.py#L278-L286
2017-04-10 7:09 GMT+02:00 sarfaraz ahmed <[email protected]>:
> Hello Friends,
>
> I have attempted to make CustomUser model in django to signin using email.
>
> I am using password_reset view when I am getting this error. I checked
> password_reset view and found i am getting error during this line
>
> form.save(**opts)
>
> in password_reset
>
> ------------------------------------------------------------
> ------------------------------------------------------------
> ----------------------------------------------------------------
> URL.py
> ------------------------------------------------------------
> --------------------------------
> from django.conf.urls import url,include
>
> from django.conf.urls import url
> from django.conf.urls import include
>
>
> from . import views
> from views import *
>
>
> from django.contrib.auth import views as auth_views
> from django.contrib.auth.views import password_reset,password_reset_done
>
>
> app_name ="user_management"
>
> urlpatterns = [
> url(r'^login/',login,name='login'),
> url(r'^auth_view/',auth_view, name='auth_view'),
> url(r'^signup_success/',signup_success,name='signup_
> success'),
> url(r'^signup/',signup,name='signup'),
> url(r'^logout/',logout,name='logout'),
> url(r'^signup_confirm/(?P<activation_key>\w+)',signup_
> confirm,name='signup_confirm'),
> url(r'^account_info/',account_info,name='account_info'),
> url(r'^user_profile/',user_profile,name='user_profile'),
> url(r'^address/',address,name='address'),
> url(r'^change_password/',change_password,name='change_
> password'),
> url(r'^add_address/',add_address,name='add_address'),
> url(r'^edit_address/(?P<id>\d+)',edit_address,name='edit_
> address'),
> url(r'^delete_address/(?P<id>\d+)',delete_address,name='
> delete_address'),
> url(r'^change_password/',change_password,name='change_
> password'),
> url(r'^email_test/',email_test,name='email_test'),
> url(r'^password_reset/$', auth_views.password_reset,{'
> post_reset_redirect':'/password_reset/done','template_name':'user_
> management/password_reset.html','email_template_name':'
> user_management/password_reset_email.html'} , name='password_reset'),
> url(r'^password_reset/done/$', auth_views.password_reset_done,
> {'template_name':'user_management/password_reset_
> done.html'},name='password_reset_done'),
> url(r'^reset/(?P<uidb64>[0-9A-
> Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$',
> auth_views.password_reset_confirm,{'template_name':'
> user_managment/password_reset_confirm.html'},name='password_
> reset_confirm'),
> url(r'^reset/done/$', auth_views.password_reset_complete,
> {'template_name':'user_management/password_reset_complete.html'},
> name='password_reset_complete'),
>
> ]
>
> ------------------------------------------------------------
> ------------------------------------------------------------
> -----------------------
> NoReverseMatch at /password_reset/
>
> Reverse for 'password_reset_confirm' with arguments '()' and keyword
> arguments '{u'uidb64': 'Mg', u'token': u'4l3-29face0d2514fc5a70e4'}' not
> found. 0 pattern(s) tried: []
>
> Request Method: POST
> Request URL: http://127.0.0.1:8000/password_reset/
> Django Version: 1.10.5
> Exception Type: NoReverseMatch
> Exception Value:
>
> Reverse for 'password_reset_confirm' with arguments '()' and keyword
> arguments '{u'uidb64': 'Mg', u'token': u'4l3-29face0d2514fc5a70e4'}' not
> found. 0 pattern(s) tried: []
>
> Exception Location:
> C:\Python27\lib\site-packages\django-1.10.5-py2.7.egg\django\urls\resolvers.py
> in _reverse_with_prefix, line 392
> Python Executable: C:\Python27\python.exe
> Python Version: 2.7.9
> Python Path:
>
> ['G:\\DJANGO_Project\\project1',
> 'C:\\Python27\\lib\\site-packages\\django_extensions-1.4.9-py2.7.egg',
> 'C:\\Python27\\lib\\site-packages\\six-1.9.0-py2.7.egg',
> 'C:\\Python27\\lib\\site-packages\\werkzeug-0.9.6-py2.7.egg',
> 'C:\\Python27\\lib\\site-packages\\django_cron-0.3.5-py2.7.egg',
> 'C:\\Python27\\lib\\site-packages\\django_common_helpers-0.6.3-py2.7.egg',
> 'C:\\Python27\\lib\\site-packages\\south-1.0.2-py2.7.egg',
> 'C:\\Python27\\lib\\site-packages\\django_crontab-0.6.0-py2.7.egg',
> 'C:\\Python27\\lib\\site-packages\\django_kronos-0.6-py2.7.egg',
> 'C:\\Python27\\lib\\site-packages\\python_crontab-1.9.1-py2.7.egg',
> 'C:\\Python27\\lib\\site-packages\\django_chronograph-0.3.1-py2.7.egg',
> 'C:\\Python27\\lib\\site-packages\\python_dateutil-1.5-py2.7.egg',
> 'C:\\Python27\\lib\\site-packages\\crontab-0.20.2-py2.7.egg',
> 'C:\\Python27\\lib\\site-packages\\django_chroniker-0.6.8-py2.7.egg',
> 'C:\\Python27\\lib\\site-packages\\psutil-2.2.0-py2.7-win32.egg',
> 'C:\\Python27\\lib\\site-packages\\celery-3.1.17-py2.7.egg',
> 'C:\\Python27\\lib\\site-packages\\kombu-3.0.24-py2.7.egg',
> 'C:\\Python27\\lib\\site-packages\\billiard-3.3.0.19-py2.7-win32.egg',
> 'C:\\Python27\\lib\\site-packages\\pytz-2014.10-py2.7.egg',
> 'C:\\Python27\\lib\\site-packages\\amqp-1.4.6-py2.7.egg',
> 'C:\\Python27\\lib\\site-packages\\anyjson-0.3.3-py2.7.egg',
> 'C:\\Python27\\lib\\site-packages\\django_celery-3.1.16-py2.7.egg',
> 'C:\\Python27\\lib\\site-packages\\django_kombu-0.9.4-py2.7.egg',
> 'C:\\Python27\\lib\\site-packages\\django_windows_tools-0.1.1-py2.7.egg',
> 'C:\\Python27\\lib\\site-packages\\elasticsearch-1.3.0-py2.7.egg',
> 'C:\\Python27\\lib\\site-packages\\urllib3-1.10.1-py2.7.egg',
> 'C:\\Python27\\lib\\site-packages\\beautifulsoup-3.2.1-py2.7.egg',
> 'C:\\Python27\\lib\\site-packages\\xmlutils-1.1-py2.7.egg',
> 'C:\\Python27\\lib\\site-packages\\pillow-2.9.0-py2.7-win32.egg',
> 'C:\\Python27\\lib\\site-packages\\requests-2.7.0-py2.7.egg',
> 'C:\\Python27\\lib\\site-packages\\openpyxl-2.3.4-py2.7.egg',
> 'C:\\Python27\\lib\\site-packages\\et_xmlfile-1.0.1-py2.7.egg',
> 'C:\\Python27\\lib\\site-packages\\jdcal-1.2-py2.7.egg',
> 'C:\\Python27\\lib\\site-packages\\xlrd-0.9.4-py2.7.egg',
> 'C:\\Python27\\lib\\site-packages\\webcolors-1.5-py2.7.egg',
> 'C:\\Python27\\lib\\site-packages\\bpython-0.15-py2.7.egg',
> 'C:\\Python27\\lib\\site-packages\\greenlet-0.4.9-py2.7-win32.egg',
> 'C:\\Python27\\lib\\site-packages\\curtsies-0.2.6-py2.7.egg',
> 'C:\\Python27\\lib\\site-packages\\pygments-2.1.3-py2.7.egg',
> 'C:\\Python27\\lib\\site-packages\\wcwidth-0.1.6-py2.7.egg',
> 'C:\\Python27\\lib\\site-packages\\blessings-1.6-py2.7.egg',
> 'C:\\Python27\\lib\\site-packages\\dnspython-1.14.0-py2.7.egg',
> 'C:\\Python27\\lib\\site-packages\\django-1.10.5-py2.7.egg',
> 'C:\\Windows\\system32\\python27.zip',
> 'C:\\Python27\\DLLs',
> 'C:\\Python27\\lib',
> 'C:\\Python27\\lib\\plat-win',
> 'C:\\Python27\\lib\\lib-tk',
> 'C:\\Python27',
> 'C:\\Python27\\lib\\site-packages',
> 'C:\\Python27\\lib\\site-packages\\win32',
> 'C:\\Python27\\lib\\site-packages\\win32\\lib',
> 'C:\\Python27\\lib\\site-packages\\Pythonwin']
>
> Server time: Mon, 10 Apr 2017 05:02:00 +0000
> Error during template rendering
>
> In template G:\DJANGO_Project\project1\user_management\templates\
> user_management\password_reset_email.html, error at line *5*
> Reverse for 'password_reset_confirm' with arguments '()' and keyword
> arguments '{u'uidb64': 'Mg', u'token': u'4l3-29face0d2514fc5a70e4'}' not
> found. 0 pattern(s) tried: [] 1 {% autoescape off %} 2 To initiate the
> password reset process for your {{ user.get_username }} Arham Account, 3
> click the link below: 4 5 {{ protocol }}://{{ domain }}{% url
> 'password_reset_confirm' uidb64=uid token=token %} 6 7 If clicking the
> link above doesn't work, please copy and paste the URL in a new browser 8
> window instead. 9 10 Sincerely, 11 The Arham Collections 12 {%
> endautoescape %}
> ------------------------------------------------------------
> ------------------------------------------------------------
> --------------------------------
> ------------------------------------------------------------
> ------------------------------------------------------------
> -----------------------------------
> Trace back
> ------------------------------------------------------------
> ------------------------------------------------------------
> --------------------------------
> Environment:
>
>
> Request Method: POST
> Request URL: http://127.0.0.1:8000/password_reset/
>
> Django Version: 1.10.5
> Python Version: 2.7.9
> Installed Applications:
> ['django.contrib.admin',
> 'django.contrib.auth',
> 'django.contrib.contenttypes',
> 'django.contrib.sessions',
> 'django.contrib.messages',
> 'django.contrib.staticfiles',
> 'main_app',
> 'user_management',
> 'product_management']
> Installed Middleware:
> ['django.middleware.security.SecurityMiddleware',
> 'django.contrib.sessions.middleware.SessionMiddleware',
> 'django.middleware.common.CommonMiddleware',
> 'django.middleware.csrf.CsrfViewMiddleware',
> 'django.contrib.auth.middleware.AuthenticationMiddleware',
> 'django.contrib.messages.middleware.MessageMiddleware',
> 'django.middleware.clickjacking.XFrameOptionsMiddleware']
>
>
> Template error:
> In template G:\DJANGO_Project\project1\user_management\templates\
> user_management\password_reset_email.html, error at line 5
> Reverse for 'password_reset_confirm' with arguments '()' and keyword
> arguments '{u'uidb64': 'Mg', u'token': u'4l3-29face0d2514fc5a70e4'}' not
> found. 0 pattern(s) tried: [] 1 : {% autoescape off %}
> 2 : To initiate the password reset process for your {{
> user.get_username }} Arham Account,
> 3 : click the link below:
> 4 :
> 5 : {{ protocol }}://{{ domain }} {% url 'password_reset_confirm'
> uidb64=uid token=token %}
> 6 :
> 7 : If clicking the link above doesn't work, please copy and paste the
> URL in a new browser
> 8 : window instead.
> 9 :
> 10 : Sincerely,
> 11 : The Arham Collections
> 12 : {% endautoescape %}
>
> Traceback:
>
> File "C:\Python27\lib\site-packages\django-1.10.5-py2.7.
> egg\django\core\handlers\exception.py" in inner
> 39. response = get_response(request)
>
> File "C:\Python27\lib\site-packages\django-1.10.5-py2.7.
> egg\django\core\handlers\base.py" in _get_response
> 187. response = self.process_exception_by_middleware(e,
> request)
>
> File "C:\Python27\lib\site-packages\django-1.10.5-py2.7.
> egg\django\core\handlers\base.py" in _get_response
> 185. response = wrapped_callback(request,
> *callback_args, **callback_kwargs)
>
> File "C:\Python27\lib\site-packages\django-1.10.5-py2.7.
> egg\django\contrib\auth\views.py" in inner
> 47. return func(*args, **kwargs)
>
> File "C:\Python27\lib\site-packages\django-1.10.5-py2.7.
> egg\django\utils\decorators.py" in _wrapped_view
> 149. response = view_func(request, *args, **kwargs)
>
> File "C:\Python27\lib\site-packages\django-1.10.5-py2.7.
> egg\django\contrib\auth\views.py" in password_reset
> 212. form.save(**opts)
>
> File "C:\Python27\lib\site-packages\django-1.10.5-py2.7.
> egg\django\contrib\auth\forms.py" in save
> 291. user.email, html_email_template_name=html_
> email_template_name,
>
> File "C:\Python27\lib\site-packages\django-1.10.5-py2.7.
> egg\django\contrib\auth\forms.py" in send_mail
> 240. body = loader.render_to_string(email_template_name,
> context)
>
> File
> "C:\Python27\lib\site-packages\django-1.10.5-py2.7.egg\django\template\loader.py"
> in render_to_string
> 68. return template.render(context, request)
>
> File "C:\Python27\lib\site-packages\django-1.10.5-py2.7.
> egg\django\template\backends\django.py" in render
> 66. return self.template.render(context)
>
> File
> "C:\Python27\lib\site-packages\django-1.10.5-py2.7.egg\django\template\base.py"
> in render
> 208. return self._render(context)
>
> File
> "C:\Python27\lib\site-packages\django-1.10.5-py2.7.egg\django\template\base.py"
> in _render
> 199. return self.nodelist.render(context)
>
> File
> "C:\Python27\lib\site-packages\django-1.10.5-py2.7.egg\django\template\base.py"
> in render
> 994. bit = node.render_annotated(context)
>
> File
> "C:\Python27\lib\site-packages\django-1.10.5-py2.7.egg\django\template\base.py"
> in render_annotated
> 961. return self.render(context)
>
> File "C:\Python27\lib\site-packages\django-1.10.5-py2.7.
> egg\django\template\defaulttags.py" in render
> 39. output = self.nodelist.render(context)
>
> File
> "C:\Python27\lib\site-packages\django-1.10.5-py2.7.egg\django\template\base.py"
> in render
> 994. bit = node.render_annotated(context)
>
> File
> "C:\Python27\lib\site-packages\django-1.10.5-py2.7.egg\django\template\base.py"
> in render_annotated
> 961. return self.render(context)
>
> File "C:\Python27\lib\site-packages\django-1.10.5-py2.7.
> egg\django\template\defaulttags.py" in render
> 439. url = reverse(view_name, args=args, kwargs=kwargs,
> current_app=current_app)
>
> File
> "C:\Python27\lib\site-packages\django-1.10.5-py2.7.egg\django\urls\base.py"
> in reverse
> 91. return force_text(iri_to_uri(resolver._reverse_with_prefix(view,
> prefix, *args, **kwargs)))
>
> File
> "C:\Python27\lib\site-packages\django-1.10.5-py2.7.egg\django\urls\resolvers.py"
> in _reverse_with_prefix
> 392. (lookup_view_s, args, kwargs, len(patterns), patterns)
>
> Exception Type: NoReverseMatch at /password_reset/
> Exception Value: Reverse for 'password_reset_confirm' with arguments '()'
> and keyword arguments '{u'uidb64': 'Mg', u'token':
> u'4l3-29face0d2514fc5a70e4'}' not found. 0 pattern(s) tried: []
> -------------------------------------------------
> I hope this information is enough
> --
> Thanks with regards,
> Sarfaraz Ahmed
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/CAEPJdiwPcS1pSef2m6h%2BpGecvHfVJAEf-
> wXGmmvT0BPGpKbBBA%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAEPJdiwPcS1pSef2m6h%2BpGecvHfVJAEf-wXGmmvT0BPGpKbBBA%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
--
Cordialement, Ludovic Coues
+33 6 14 87 43 42
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/CAEuG%2BTZKxo%3DXFOjt2Cfh%2BHemN9K3QFpNLJ8Q7viggJuJ_v4LQw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.