I am writing a django web app and using jquery-ui for the user interface. I am using django-registration to take care of user registration.
Basically, what I'm trying to do, is instead of having a separate Login page, I wan the login page to be a modal dialog, so that you click on a link, and if you need to login, a popup shows up and you can login from there. For this part, I'm using jquery-ui modal form, and am basically just displaying a login form that is normally hidden.
However, I can only get it to work if the url for the page looks like this:
url(r'^$',
auth_views.login,
{'template_name': 'index.html'}),
Since I want the login modal window to pop up whenever the user wants to do something that requires login, I will need it on multiple pages. But I don't want to make all the urls look like the above.
I saw another question on the site that addresses the issue: Django authentication and Ajax - URLs that require login but I don't fully understand the answer. I'm still fairly new to Django and javascript, so was wondering if someone could provide a little more guidance?
Here is the part in "index.html" for the form:
<div id="dialog-form" title="LOGIN">
<form method="post" action="?next={{ next|default:"/" }}">
{% csrf_token %}
<dl>
<dt><label for="id_username">Username:</label>{% if form.username.errors %} <span class="error">{{ form.username.errors|join:", " }}</span>{% endif %}</dt>
<dd>{{ form.username }}</dd>
<dt><label for="id_password">Password:</label>{% if form.password.errors %} <span class="error">{{ form.password.errors|join:", " }}</span>{% endif %}</dt>
<dd>{{ form.password }}</dd>
<dt><input type="submit" value="Log in" /></dt>
</dl>
</form>
</div>
<button id="login">LOGIN</button>
And here's the javascript:
<script>
$(function() {
$( "#dialog-form" ).dialog({
autoOpen: false,
height: 500,
width: 550,
modal: true,
buttons: {
Close: function() {
$( this ).dialog( "close" );
}
},
close: function() {
allFields.val( "" ).removeClass( "ui-state-error" );
}
});
$( "#login" ).click(function() {
$( "#dialog-form" ).dialog( "open" );
});
});
</script>
Thank you in advance for your help.