django registration not loading the registration_complete.html template - django

I am using Django 1.3 and django-registration 0.8. I am trying to use the RegistrationFormUniqueEmail class to enforce unique emails.
The form validation works but once the form is submitted, it does not load the registration_complete.html template. The page refreshes, and the url goes to register/complete, but it just displays an empty registration_form.html template.
I suspect my urls.py is incorrectly configured:
from registration.forms import RegistrationFormUniqueEmail
urlpatterns = patterns('',
url(r'^accounts/register/', 'registration.views.register', {'form_class':RegistrationFormUniqueEmail,'backend':'registration.backends.default.DefaultBackend' }),
url(r'^accounts/', include('registration.urls')),
Any suggestions? I'd prefer not to upgrade Django.

Try adding a $ to the end of your first regex. At the moment, it matches both /accounts/register/ and /accounts/register/complete/.
url(r'^accounts/register/$', 'registration.views.register', {'form_class':RegistrationFormUniqueEmail,'backend':'registration.backends.default.DefaultBackend' }),

Related

Login Required Django Classed Based View

Totally beginner question.
I have this view in my app Foo:
class PaymentsView(LoginRequiredMixin, CreateView):
login_url = '/login/'
redirect_field_name = 'redirect_to'
# -- Omitted ...
I have read the django documentation but I didn't see where to put my file "login.html" and how can I set the url for that. When I run the code show the 404 error.
Setting login_url will redirect to a URL within your project, which is then handled by URL Dispatcher. You'll need to include a path to that URL within your URLConf, just like you would with any other URL:
urls.py:
from django.urls import path
from . import views
urlpatterns = [
path('login/', views.login),
]
You'll then need to write a view to handle the login. Django provides pre-written views and URL patterns that handle this with its login system.

How can I fix my Wagtail URL namespace and explorer when adding wagtail to a current project?

My issue is my URL is coming up mysite.com/test-news-1/ instead of mysite.com/news/test-news-1/
I've started a new project using cookiecutter-django. I then wanted to add wagtail cms to the project and followed the docs to do so.
I get the wagtail admin page up fine, at /cms/ instead of /admin/ like it says to do on this page - http://docs.wagtail.io/en/v1.3.1/getting_started/integrating_into_django.html
I added a few apps just to practice and get used to wagtail, one directly copied from the wagtail blog example. This is where my issue starts.
The wagtail admin Explorer does not list my apps like it shows on the wagtail site https://wagtail.io/features/explorer/, instead it just says "Welcome to your new Wagtail site!" When I select Add Child Page it allows me to select the app pages I have set up and seems to go by my models just fine. But when I post something and click go to live site it comes up as mysite.com/blog1/ instead of mysite.com/blog/blog1/
I believe my problem that I dont understand the final part of the doc page that I linked above. It says,
Note that there’s one small difference when not using the Wagtail
project template: Wagtail creates an initial homepage of the basic
type Page, which does not include any content fields beyond the title.
You’ll probably want to replace this with your own HomePage class -
when you do so, ensure that you set up a site record (under Settings /
Sites in the Wagtail admin) to point to the new homepage.
I tried adding the homepage model from the doc page, but this didn't seem to help at all.
I'm very inexperienced, this is my urls.py file, if you need to see other files please let me know.
urls.py
from __future__ import unicode_literals
from django.conf import settings
from django.conf.urls import include, url
from django.conf.urls.static import static
from django.contrib import admin
from django.views.generic import TemplateView
from django.views import defaults as default_views
from wagtail.wagtailadmin import urls as wagtailadmin_urls
from wagtail.wagtaildocs import urls as wagtaildocs_urls
from wagtail.wagtailcore import urls as wagtail_urls
urlpatterns = [
url(r'^$', TemplateView.as_view(template_name='pages/home.html'), name="home"),
url(r'^about/$', TemplateView.as_view(template_name='pages/about.html'), name="about"),
# Django Admin, use {% url 'admin:index' %}
url(settings.ADMIN_URL, include(admin.site.urls)),
# User management
url(r'^users/', include("contestchampion.users.urls", namespace="users")),
url(r'^accounts/', include('allauth.urls')),
# Your stuff: custom urls includes go here
# Wagtail cms
url(r'^cms/', include(wagtailadmin_urls)),
url(r'^documents/', include(wagtaildocs_urls)),
url(r'', include(wagtail_urls)),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
if settings.DEBUG:
# This allows the error pages to be debugged during development, just visit
# these url in browser to see how these error pages look like.
urlpatterns += [
url(r'^400/$', default_views.bad_request, kwargs={'exception': Exception("Bad Request!")}),
url(r'^403/$', default_views.permission_denied, kwargs={'exception': Exception("Permission Denied")}),
url(r'^404/$', default_views.page_not_found, kwargs={'exception': Exception("Page not Found")}),
url(r'^500/$', default_views.server_error),
]
These two url confs are in conflict =
url(r'^$', TemplateView.as_view(template_name='pages/home.html'), name="home"),
url(r'', include(wagtail_urls)),
One must change, otherwise Django will always resolve the base url of `yourdomain.com/' to the first entry. One easy way to fix this is to update the second-
url(r'^content/', include(wagtail_urls)),
Now your Wagtail root page will be accessible at yourdomain.com/content.
As for mysite.com/blog/blog1/ not coming up, that Url would assume that, from your Wagtail root page, there's a page w/ slug 'blog', and then a child page of that with slug blog1. The tree structure of your Wagtail site determines the URLs by default. If you want to override that you'll have to use the RoutablePageMixin as described here.

What takes priority of urls out of Django and AngularJS?

I am using Django with Angular... When I refresh my pages, I would prefer Angular to handle routing. So I need to render layout.html (via django), and after that let Angular manage the urls and routing to the correct controller.
For example in Django:
urls.py:
urlpatterns = patterns('',
url(r'^api/', include(v1_api.urls)),
url(r'^.*$', 'home.views.index'),
)
views.py
def index(request):
return render(request, 'layout.html', {})
But the priority of Django is not according to the number of lines written. Because now after refreshing, the urls that start with api, render index as well. It means Django didn't understand that the urls that start by api have higher priority.
So, whats priority of urls in Django, and has using Angular changed this?
Django will always return the first matching pattern.
i found the solution:
in url.py i changed reg-exp, instead of
url(r'^.*$', 'home.views.index'),
i used :
url(r'^.*/$', 'home.views.index'),
now if Django didn't find any matches, shows index.

Can't get django registration to work

i have installed django-registration on django 1.3, I can't get it to work.
When i hit submit on the accounts/register/ page, it redirects to accounts/registration which isn't in the default URL's.
I can't seem to pass my post data to the register function. Help?
Does your urls.py have:
import registration
...
urlpatterns += patterns(
url(r'^accounts/', include('registration.backends.default.urls')),
)
Do you have all the appropriate templates installed in a template directory?
https://github.com/yourcelf/django-registration-defaults

Django-nonrel + Django-registration problem: unexpected keyword argument 'uidb36' when resetting password

I'm using Django-nonrel with registration app. Things seem to be working fine, except when I try to reset my password. When clicking on reset-password link sent to me in email, Django produces error message:
password_reset_confirm() got an unexpected keyword argument 'uidb36'
My question: has anybody seen it and knows what's the cure?
EDIT:
The problem is caused by registration\auth_urls.py - they duplicate entries in django\contrib\auth\urls.py, circumwenting patched version of the file in Django-nonrel.
Any ideas why is it there and can I actually remove it or fix it otherwise?
Django 1.6 uses base 64 encoding for the User's ID instead of base 36 encoding.
If you have any custom password reset URLs, you will need to update them by replacing uidb36 with uidb64 and the dash that follows that pattern with a slash. Also add "_", "\" and "-" to the list of characters that may match the uidb64 pattern.
For example this line in urls.py in Django 1.5-:
url(r'^reset/(?P<uidb36>[0-9A-Za-z]+)-(?P<token>.+)/$',
'django.contrib.auth.views.password_reset_confirm',
name='password_reset_confirm'),
Will need to be changed to this in Django 1.6+:
url(r'^reset/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>.+)/$',
'django.contrib.auth.views.password_reset_confirm',
name='password_reset_confirm'),
Here is the official changelog which details the change:
https://docs.djangoproject.com/en/1.6/releases/1.6/#django-contrib-auth-password-reset-uses-base-64-encoding-of-user-pk
My solution was to comment out urlpatterns defined in registration\auth_urls.py, and redefine them as a copy of urlpatterns defined in django.contrib.auth.
Here's my auth_urls.py after the change:
"""
URL patterns for the views included in ``django.contrib.auth``.
Including these URLs (via the ``include()`` directive) will set up the
following patterns based at whatever URL prefix they are included
under:
* User login at ``login/``.
* User logout at ``logout/``.
* The two-step password change at ``password/change/`` and
``password/change/done/``.
* The four-step password reset at ``password/reset/``,
``password/reset/confirm/``, ``password/reset/complete/`` and
``password/reset/done/``.
The default registration backend already has an ``include()`` for
these URLs, so under the default setup it is not necessary to manually
include these views. Other backends may or may not include them;
consult a specific backend's documentation for details.
"""
from django.conf.urls.defaults import *
#from django.contrib.auth import views as auth_views
from django.contrib.auth import urls as auth_urls
urlpatterns = auth_urls.urlpatterns
'''
Commented out, this is what caused my problems:
urlpatterns = patterns('',
url(r'^login/$',
auth_views.login,
{'template_name': 'registration/login.html'},
name='auth_login'),
url(r'^logout/$',
auth_views.logout,
{'template_name': 'registration/logout.html'},
name='auth_logout'),
url(r'^password/change/$',
auth_views.password_change,
name='auth_password_change'),
url(r'^password/change/done/$',
auth_views.password_change_done,
name='auth_password_change_done'),
url(r'^password/reset/$',
auth_views.password_reset,
name='auth_password_reset'),
url(r'^password/reset/confirm/(?P<uidb36>[0-9A-Za-z]+)-(?P<token>.+)/$',
auth_views.password_reset_confirm,
name='auth_password_reset_confirm'),
url(r'^password/reset/complete/$',
auth_views.password_reset_complete,
name='auth_password_reset_complete'),
url(r'^password/reset/done/$',
auth_views.password_reset_done,
name='auth_password_reset_done'),
)
'''
I just had to change the uidb36 argument to uidb64, like so:
FROM:
url(r'^password/reset/confirm/(?P<uidb36>[0-9A-Za-z]+)-(?P<token>.+)/$',
TO:
url(r'^password/reset/confirm/(?P<uidb64>[0-9A-Za-z]+)-(?P<token>.+)/$',
Then password resets began working again.
I guess your password_reset_confirm url in urls.py looks something similar to
url(r'^accounts/password_reset/(?P[0-9A-Za-z]{1,13})-(?P[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$',
password_reset_confirm,
{'post_reset_redirect' : '/accounts/password_reset/complete/'},name="password_reset_confirm"),
and your link in password_reset_email.html looks like
{{ protocol }}://{{ domain }}{% url 'password_reset_confirm' uidb36=uid token=token %}
Just change uib36 to uib64 both the places,it works.