{"id":339,"date":"2013-12-05T08:49:48","date_gmt":"2013-12-05T07:49:48","guid":{"rendered":"http:\/\/joost.vunderink.net\/blog\/?p=339"},"modified":"2013-12-05T08:49:48","modified_gmt":"2013-12-05T07:49:48","slug":"user-registration-in-django-with-django-allauth","status":"publish","type":"post","link":"https:\/\/joost.vunderink.net\/blog\/2013\/12\/05\/user-registration-in-django-with-django-allauth\/","title":{"rendered":"User registration in django with django-allauth"},"content":{"rendered":"<p>While working on my <a title=\"Contract Bridge\" href=\"http:\/\/en.wikipedia.org\/wiki\/Contract_bridge\">bridge<\/a> website (at this moment, very much in <a title=\"Bridge It\" href=\"http:\/\/cara.sente.nl:8888\">alpha state<\/a>), which is written in <a title=\"Django\" href=\"http:\/\/djangoproject.com\">Django<\/a>, I had arrived at the point where I wanted users to be able to register themselves, instead of me having to add test users manually.<\/p>\n<p>So I looked at <a href=\"https:\/\/docs.djangoproject.com\/en\/dev\/topics\/auth\/\">Django&#8217;s user authentication documentation<\/a> online. I was surprised that there wasn&#8217;t anything about registration. Apparently, I had to find another way to do that. Obviously, I&#8217;m not the first person to be in this situation so there had to be a module or plugin for Django that does user registration. And indeed there are. But which one to use?<\/p>\n<p>Since I&#8217;m an <a href=\"http:\/\/en.wikipedia.org\/wiki\/Irc\">IRC<\/a> user, it was logical to visit <a href=\"https:\/\/code.djangoproject.com\/wiki\/IrcFAQ\">#django on freenode<\/a> and ask this question. Almost immediately, someone replied to use <a href=\"https:\/\/github.com\/pennersr\/django-allauth\">django-allauth<\/a>, and nobody disagreed. The django-allauth page looks good: recent activity and extensive documentation.<\/p>\n<p>I typed\u00a0<code>pip install django-allauth<\/code> in my virtual environment and started to change my code to add user registration:<\/p>\n<ul>\n<li>Edited settings.py<\/li>\n<li>Edited urls.py<\/li>\n<li>Ran manage.py syncdb<\/li>\n<li>Did not do the Site object steps, because initially I don&#8217;t want social app integration<\/li>\n<\/ul>\n<p>When I visited my development site after that, the login and logout pages had been replaced by django-allauth&#8217;s version, and logging in with existing users worked. So far, so good!<\/p>\n<p>I noticed that, by default, the login page redirects to <code>\/accounts\/profile\/<\/code> after logging in successfully. This page did not exist and gave a &#8220;page not found&#8221; error. At first, I thought that I had done something wrong with configuring django-allauth, but after reading the FAQ, I learned that this is by design. Profile management is not provided by django-allauth; you have to do that some other way.<\/p>\n<p>When trying to register a new user, and filling in all fields on the registration page, I got the following error:<\/p>\n<p><a href=\"http:\/\/joost.vunderink.net\/blog\/wp-content\/uploads\/2013\/12\/Screen-Shot-2013-12-01-at-10.09.13.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-340\" alt=\"Screen Shot 2013-12-01 at 10.09.13\" src=\"http:\/\/joost.vunderink.net\/blog\/wp-content\/uploads\/2013\/12\/Screen-Shot-2013-12-01-at-10.09.13-300x104.png\" width=\"300\" height=\"104\" srcset=\"https:\/\/joost.vunderink.net\/blog\/wp-content\/uploads\/2013\/12\/Screen-Shot-2013-12-01-at-10.09.13-300x104.png 300w, https:\/\/joost.vunderink.net\/blog\/wp-content\/uploads\/2013\/12\/Screen-Shot-2013-12-01-at-10.09.13.png 561w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Uh, what? Connection refused? Ah, I guess sending of the registration confirmation email failed, because I don&#8217;t have a mail server running on my development server. The FAQ of django-allauth mentions this as well. It suggests to add the following line to <code>settings.py<\/code>:<\/p>\n<pre>EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'<\/pre>\n<p>I did, and after that, registration worked. The registration email was not sent but printed in the django log.<\/p>\n<p>The last thing to do, was to get the login and logout pages in the style of my website. This was not explained in the django-allauth documentation, but searching for an answer made me realise that this is done the same way as overriding other templates:<\/p>\n<pre>cd ~\/venv\/bridgedb\/lib\/python2.7\/site-packages\/allauth\/templates\/\r\ncp account\/base.html ~\/src\/bridgedb\/templates\/account\/\r\ncp account\/login.html ~\/src\/bridgedb\/templates\/account\/\r\ncp account\/logout.html ~\/src\/bridgedb\/templates\/account\/<\/pre>\n<p>Then I edited the copied templates in <code>~\/src\/bridgedb\/templates\/account<\/code> and changed them to match the rest of my pages.<\/p>\n<p>In doing this, I noticed that if you use the template <code>base.html<\/code> as base for all your pages, and <code>{% block content %}<\/code> as content block, the django-allauth pages are styled correctly without any effort. But I was using skeleton.html, so that didn&#8217;t work for me.<\/p>\n<p>All in all, pretty easy to get this to work. Thanks, <a href=\"https:\/\/github.com\/pennersr\">Raymond<\/a>, for this module!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>While working on my bridge website (at this moment, very much in alpha state), which is written in Django, I had arrived at the point where I wanted users to be able to register themselves, instead of me having to &hellip; <a href=\"https:\/\/joost.vunderink.net\/blog\/2013\/12\/05\/user-registration-in-django-with-django-allauth\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[157,156,10],"tags":[163,158,164,225,162,160,161,159],"class_list":["post-339","post","type-post","status-publish","format-standard","hentry","category-django","category-python","category-software-development","tag-allauth","tag-auth","tag-bridge","tag-django","tag-django-allauth","tag-login","tag-logout","tag-webauth"],"_links":{"self":[{"href":"https:\/\/joost.vunderink.net\/blog\/wp-json\/wp\/v2\/posts\/339"}],"collection":[{"href":"https:\/\/joost.vunderink.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/joost.vunderink.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/joost.vunderink.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/joost.vunderink.net\/blog\/wp-json\/wp\/v2\/comments?post=339"}],"version-history":[{"count":2,"href":"https:\/\/joost.vunderink.net\/blog\/wp-json\/wp\/v2\/posts\/339\/revisions"}],"predecessor-version":[{"id":342,"href":"https:\/\/joost.vunderink.net\/blog\/wp-json\/wp\/v2\/posts\/339\/revisions\/342"}],"wp:attachment":[{"href":"https:\/\/joost.vunderink.net\/blog\/wp-json\/wp\/v2\/media?parent=339"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/joost.vunderink.net\/blog\/wp-json\/wp\/v2\/categories?post=339"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/joost.vunderink.net\/blog\/wp-json\/wp\/v2\/tags?post=339"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}