I'm trying to send a custom email template with the reset token. But it keeps sending raw HTML no matter what I do. I have previous experience of doing exactly the same thing without any problem with the Django and Django rest framework.
Here's how I did it,
urls.py
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('store.urls')),
path('', include('django.contrib.auth.urls')),
]
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
store/urls.py
...
path('password_reset',
auth_views.PasswordResetView.as_view(
template_name='registration/password_reset_form.html',
html_email_template_name='registration/html_password_reset_email.html',
email_template_name = 'registration/password_reset_email.html',
),
name='password_reset'
),
folder structure
...
templates
|-- registration
|-- html_password_reset_email.html
|-- password_reset_email.html
|-- ...
...
Note:
I tried deleting the password_reset_email.html template after that it sends the default Django email template.
Hoping for any guidance to solve the issue thanks in advance.
Finally days(3) of debugging I found my dumb mistake :(,
I was including all auth urls path('', include('django.contrib.auth.urls')) in my main urls.py file and re defining the auth.urls again in store/urls.py differently so the overriding doesn't happen correctly.
So, instead of,
path('password_reset', # <<< here
auth_views.PasswordResetView.as_view(
...
),
name='password_reset'
),
it should be,
path('password_reset/', # <<< here
auth_views.PasswordResetView.as_view(
),
name='password_reset'
),
Not gonna delete the question (^.^') #for_sake_of_dumb_fellows_like_me
Related
I don't understand why django wont render any other template , but home with this code:
urlpatterns = [
url(r'^login/', login_page),
url(r'^admin/', admin.site.urls),
url(r'^contact/', contact_page),
url(r'^about/', about_page),
url(r'$', home_page),
]
But as soon as I delete the home url , every url works just fine. Yes , I did join the base dir with the templates one. Also , it might be useful to add that Im using django 1.11. Thank you !
Django is throwing me a NoReverseMatch function but I cannot find the reason.
I did check whether I use the reverse function correctly and it seems it does. I also think it is not the custom converters I created because it throws a NoReverseMatch exception.
my forms.py:
#some link creation function
link = reverse("activate",
kwargs={"key":key, "usermail":self.cleaned_data['email']}
)
#sending the link to a user
root urls.py
urlpatterns = [
path('admin/', admin.site.urls),
path('accounts/', include('accounts.urls')),
path('accounts/', include('django.contrib.auth.urls')),
path('', TemplateView.as_view(template_name='home.html'), name='home'),
]
accounts.urls.py
path('activate/<key:user_key>/<mail:usermail>',
views.activate,
name="activate"
),
]
I just expect it to create this wonderful piece of a link and I cannot find what I am doing wrong. Maybe I am looking at the wrong place, maybe it is an integration error, I don't know. Any help is much appreciated.
edit: added the root urls.py
You should use namespace in your url include
path('accounts/', include('accounts.urls', namespace='accounts')),
and in your forms.py
link = reverse("accounts:activate",
kwargs={"user_key":key, "usermail":self.cleaned_data['email']}
)
I commented mezzanine mezzanine.accounts from settings.INSTALLED_APPS and use allauth as AUTHENTICATION_BACKEND
settings.py
AUTHENTICATION_BACKENDS = (
"django.contrib.auth.backends.ModelBackend",
"allauth.account.auth_backends.AuthenticationBackend"
)
urls.py:
urlpatterns += [
url(r"^$", include("movies.urls")),
url("^blog2", blog_post_list, name="home"),
url(r"^admin/", include(admin.site.urls)),
url(r"^movies/", include("movies.urls", namespace="movies")),
url(r"^faq/", include("fack.urls")),
url(r"^accounts/", include("allauth.urls")),
url(r'^captcha/', include('captcha.urls')),
url(r'^jsi18n/$', JavaScriptCatalog.as_view(), name='javascript-catalog'),
url(r'^tz_detect/', include('tz_detect.urls')),
url(r"^h/", include("home2.urls", namespace="home2")),
url(r"^profile/", include("profile.urls", namespace="profile")),
url("^", include("mezzanine.urls")),
]
The problem is that when I go to https://localhost/blog2, that I see the base.html of allauth.accounts.
Maybe mezzanine confuses allauth accounts/base.html with its own accounts/base.html? Or maybe I'm missing something else.
url("^blog2", blog_post_list, name="home"), uses blog/blog_post_list.html as template which extends base.html, but since there's no base.html inside blog/ app it used the first it could find which was in this case allauth, hence the confusion.
I.e. creating a base.html in <project_path>/templates/base.html, use e.g. mezzanine/core/templates/base.html as a template, solves it
I recently upgraded my Django project to version 1.9.
When I try to run migrate, I am getting the following two errors:
Support for string view arguments to url() is deprecated and will be removed in Django 1.10 (got app.views.about). Pass the callable instead.
django.conf.urls.patterns() is deprecated and will be removed in Django 1.10. Update your urlpatterns to be a list of django.conf.urls.url() instances instead.
Could someone please show me the proper syntax of how to do this? A brief sample of my urls.py is below:
urlpatterns = patterns('',
url(r'^about/$', 'app.views.about',
name='about'),
)
urlpatterns += patterns('accounts.views',
url(r'^signin/$', 'auth_login',
name='login'),
)
Thank you!
Import your views directly, or your views modules:
from apps.views import about
from accounts import views as account_views
Do not use patterns at all, just use a list or tuple:
urlpatterns = [
url(r'^about/$', about,
name='about'),
]
urlpatterns += [
url(r'^signin/$', account_views.auth_login,
name='login'),
]
You should remove the quotes around views name.
So your code will be like that
urlpatterns = patterns('',
url(r'^about/$', app.views.about, #without quote!
name='about'),
)
Point 2, use lists, so your code will transform to
urlpatterns = [
url(r'^about/$', app.views.about, #without quote!
name='about'),
]
In one application's urls.py I have:
urlpatterns = patterns('app.views',
url(r'^products/$', products, name="products"),
url(r'^$', index, name="index"),
)
In base project urls.py I have:
urlpatterns = patterns('',
(r'^$', include('app.urls')),
(r'^admin/', include(admin.site.urls)),
)
Why http://127.0.0.1:8000/ - works fine with app.views.index method
while http://127.0.0.1:8000/products/ - returns 404 error and is not defined in url routes?
Spent some time on it already and can't find solution, maybe there is something simple that I miss...
Your base urls should be:
urlpatterns = patterns('',
(r'^', include('app.urls')),
(r'^admin/', include(admin.site.urls)),
)
The '$' is only used for urls. If you look at the doc, it will tell you not use the '$' when using include().
urlpatterns = patterns('',
(r'^', include('app.urls')),
(r'^admin/', include(admin.site.urls)),
)
worked fine.
I was having the same issue while using path() in Django URLs.
The simple fix is you don't have to use the slash at the end of the path otherwise Django will take that URL as a complete URL and will not go to the next urls.py file
//this will not work
path('/', include('app.urls'), name='profile_page')
// but this will work
path('', include('app.urls'), name='profile_page')