Django-registration custom urls
<p>I've used django-registration (<a href="https://django-registration.readthedocs.io/en/latest/index.html" rel="nofollow">the app</a>, HMAC) for user registration and login. Everything works fine, but I would like to have the login form at <a href="http://localhost:8000/" rel="nofollow">http://localhost:8000/</a>, instead of /accounts/login/. What would be the cleanest way to accomplish this?</p>

<p>When just copying the form from login.html to my index.html file, which provides the view of the main page, it (obviously (?)) doesn't work. I'm using django 1.9.6 and django-registration 2.1. Please note that I haven't got 'registration' in INSTALLED_APPS in the setting.py file, since that wasn't needed according to the docs.</p>

<p>This is my login.html file:</p>

<pre><code>{% extends "mysite/base.html" %}
{% load i18n %}

{% block content %}
&lt;form method="post" action="."&gt;
  {% csrf_token %} 
  {{ form.as_p }}

  &lt;input type="submit" value="{% trans 'Log in' %}" /&gt;
  &lt;input type="hidden" name="next" value="{{next}}" /&gt;
&lt;/form&gt;

&lt;p&gt;{% trans "Forgot password" %}? &lt;a href="{% url 'auth_password_reset' %}"&gt;{% trans "Reset it" %}&lt;/a&gt;!&lt;/p&gt;
&lt;p&gt;{% trans "Not member" %}? &lt;a href="{% url 'registration_register' %}"&gt;{% trans "Register" %}&lt;/a&gt;!&lt;/p&gt;
{% endblock %}
</code></pre>

<p>And my urls.py file:</p>

<pre><code>from django.conf.urls import include, url
from django.contrib import admin
from . import views

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^$', views.index, name='index'),
    url(r'^accounts/', include('registration.backends.hmac.urls')),
    url(r'^groups/', include('groups.urls')), #my own app
]
</code></pre>

<p>Theres a few ways to do it, and it really depends on whether you care about redirects and how you like to organize your URL structure.</p>

<p>I would do something like this:</p>

<p>from django.conf.urls import include, url
from django.contrib import admin
from . import views
form registration.backends.hmac.views import login</p>

<pre><code>urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^$', views.index, name='index'),
    url(r'^accounts/login$', RedirectView.as_view(url='/login'), name='got-to-lgoin') # You have several options for this, see below
    url(r'^accounts/', include('registration.backends.hmac.urls')),  
    url(r'^login/$, login, name='login'),
    url(r'^groups/', include('groups.urls')), #my own app
]
</code></pre>

<p>Now as per the second login url, you could remove it from the hmac.urls, change it to redirect to /login, make a new custom urls file and include that, or do what I did and just add a redirect view.</p>

<p>Like I said its personal preference. If youre going to do it for more urls other than just /login and /logout, I would just make a separate urls.py file and include that. It's cleaner.</p>

<p>Hope this helps!</p>

python django django-registration