Can't get django registration to work - django

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

Related

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.

Is it possible to implement django login-authentication with out writing my own template?

my project's urls.py:
from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url('^', include('django.contrib.auth.urls')),
]
and, my app url's are:
from django.conf.urls import include, url
urlpatterns = [
url(r'^login/$', django.contrib.auth.views.login, {'template_name': 'login.html'}, name='login'),
url(r'^logout/$', django.contrib.auth.views.logout, {'template_name': 'logout.html'}, name='logout'),
]
I'm learning about django authentication. As after reading some docs, I've made a sample app and tried to implement the django authentication system on it.
Is there any built-in django template for these built in views. I've tried it without writing my own template but it throws exception. When I add my login template it works fine.
Is it possible to implement django-authentication with out writing my own 'login.html' template? Is django really having any built-in one? If it is, then how can I include it in my app?
Thanks! in advance
No, Django does not come with a login template. From the authentication docs:
It’s your responsibility to provide the html for the login template, called registration/login.html by default.
If Django came with a login template, it would probably look basic. Django doesn't know template structure, so wouldn't be able to inherit from your base template. So most people would end up creating a custom login template anyway. However, it would be easier for new users if Django included a template, however basic it looked.
Note that the authentication docs includes a sample template that you can use.
As an aside, you should either include 'django.contrib.auth.urls', or add entries for login and logout to your app's urls (this allows you to override the template name). You don't need to do both.

Django Registration with Django cms

I have integrated django-registration with django-cms. I have multilingual django-cms for my site with two languages English and french. I am facing issue in url-mapping. as django-cms has multiple language, so it attached language code after domain name. While in django-registration it consider such url as 404.
Below is flow, I putted registration button on click of that I have explicitly set to http://localhost:8000/accounts/register/ and it display registration page properly, but after successful completion of registration, it redirects to http://localhost:8000/en/accounts/register/complete/ , where language code is attached with url and django-registration says page not found. If I manually remove language code from url, it works fine.
Can anybody help me ?
url.py for project.
urlpatterns = i18n_patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'^', include('cms.urls'), name="home"),
url(r'^news/', include('multilingual_news.urls')),
url(r'^search/', include('haystack.urls')),
url(r'^member/',include('openerp_member.urls')),
(r'^accounts/',include('registration.backends.default.urls')),
)
You need to add an AppHook for Django-Registration. So what I did was:
create a new app called "cmsauth"
create the according cms_apps.py:
from cms.app_base import CMSApp
from cms.apphook_pool import apphook_pool
from django.utils.translation import ugettext_lazy as _
class RegistrationApphook(CMSApp):
name = _("RegistrationApphook")
urls = ["registration.backends.hmac.urls"]
apphook_pool.register(RegistrationApphook)
create a CMS Page like "Accounts"
link the AppHook RegistrationApphook (you might need to restart server for it to become available)
Now you should be able to reach the URLs.

django registration not loading the registration_complete.html template

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' }),

Django 1.6 and django-registration: built-in authentication views not picked up

I am trying to upgrade my webapp from Django 1.5 to Django 1.6 and as part of my set of django apps I am using django-registration 1.0.
After upgrading to Django 1.6 my app does not recognize the built-in authentication views any more. They are integrated in django registration as can be seen here, but they stopped working.
The Django release notes describe a change in the way these views should be integrated, when comparing that to the source code in the registration-app that looks fine.
I am introducing the registration urls as follows:
urlpatterns = patterns('',
...,
url(r'^accounts/', include('registration.backends.default.urls')),
)
I get the an error when requesting the built in urls such as /accounts/password/change/
django.core.urlresolvers.NoReverseMatch
NoReverseMatch: Reverse for 'password_change_done' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
Does anyone have an idea why I get a no-reverse-match error?
The reason for this error is that the django.contrib.auth.views use different url names than the registration.auth_urls ones. To patch this problem, override the default urls until django-registration gets updated for django 1.6, and use the same names as Django.
from django.contrib.auth import views as auth_views
urlpatterns = patterns('',
#override the default urls
url(r'^password/change/$',
auth_views.password_change,
name='password_change'),
url(r'^password/change/done/$',
auth_views.password_change_done,
name='password_change_done'),
url(r'^password/reset/$',
auth_views.password_reset,
name='password_reset'),
url(r'^password/reset/done/$',
auth_views.password_reset_done,
name='password_reset_done'),
url(r'^password/reset/complete/$',
auth_views.password_reset_complete,
name='password_reset_complete'),
url(r'^password/reset/confirm/(?P<uidb64>[0-9A-Za-z]+)-(?P<token>.+)/$',
auth_views.password_reset_confirm,
name='password_reset_confirm'),
#and now add the registration urls
url(r'', include('registration.backends.default.urls')),
)
Here is what I used:
url(r'', include('registration.backends.default.urls')),
url(r'', include('django.contrib.auth.urls')),
Django contrib now includes the missing urls
Background
This issue seems to have cropped again for django-registration==1.0 and Django==1.6 and is documented here on the official django-registration pull request. I used the solution provided by #Jay but it didn't work specifically for the password reset part. I ended up with this error:
Error
password_reset_confirm() got an unexpected keyword argument 'uidb36'
Solution
Instead I pulled from another django-registration repository (as mentioned in the official pull request above) by doing the following:
pip uninstall django-registration
pip install git+git://github.com/macropin/django-registration.git
Modify the code for 'urls.py' as mentioned in the post by #Jay (thanks!)
Remember this is a temporary solution until the official django-registration support is updated for Django 1.6