Hello All,

I'm completely new to Django and I've been following along with the excellent 
video series from CodingEntrepreneurs on YouTube and applying what I can to my 
project. I'm stuck on the authentication process. I don't believe that the 
request is being passed to my template correctly because in the template, I'm 
checking for authentication and if present, I'm displaying the content (or 
trying to anyway) and if not, I'm rendering a message informing the user that 
they're not logged in.

my app is title 'theapp' and I have a single view called 'index' that is 
decorated with '@login_required' and redirecting to '/accounts/login'. I have 
two users, both of which I created and activated. When I enter credentials, I'm 
redirected right back to the login page. My view is pretty simple:


def index(request):
    return render(request, 'index.html', {})


If my project is called 'thesite', in 'thesite/urls.py' I have these patterns:



urlpatterns = [

    url(r'^theapp/',
        include('theapp.urls')),

    url(r'^admin/',
        admin.site.urls),

    url(r'^login/$',
            'django.contrib.auth.views.login',
            {'template_name': 'login.html'},
            name='login')

]







In my app urls ('theapp/urls.py') I have this pattern:






urlpatterns = [
    url(r'^$',
        views.index,
        name='index'),

]






My 'base' form is like so:






<link rel="icon" href="http://getbootstrap.com/favicon.ico";>

    <title>Login</title>

    <!-- Bootstrap core CSS -->
    <link href="http://getbootstrap.com/dist/css/bootstrap.min.css"; 
rel="stylesheet">

    <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
    <link 
href="http://getbootstrap.com/assets/css/ie10-viewport-bug-workaround.css"; 
rel="stylesheet">

    <!-- Custom styles for this template -->
    <link href="http://getbootstrap.com/examples/signin/signin.css"; 
rel="stylesheet">

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media 
queries -->
    <!--[if lt IE 9]>
      <!--<script 
src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js";></script>-->
      <!--<script 
src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js";></script>-->
    <![endif]-->
  </head>

  <body>


    <div class="container">

      <form class="form-signin">
        <h2 class="form-signin-heading">Login</h2>
        <label for="inputUsername" class="sr-only">username</label>
        <input type="text" id="inputUsername" class="form-control"
               placeholder="username" required autofocus>
        <label for="inputPassword" class="sr-only">password</label>
        <input type="password" id="inputPassword" class="form-control"
               placeholder="password" required>
        <!--<div class="checkbox">-->
          <!--<label>-->
            <!--<input type="checkbox" value="remember-me"> Remember me-->
          <!--</label>-->
        <!--</div>-->
        <button class="btn btn-lg btn-primary btn-block" type="submit">Sign 
in</button>

      </form>

    </div> <!-- /container -->


    <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
    <script 
src="http://getbootstrap.com/assets/js/ie10-viewport-bug-workaround.js";></script>
  </body>
</html>








I'm extending this with 'login.html' (purely for aesthetics) like this:







{% extends "base.html" %}
{% load i18n %}
{% load crispy_forms_tags %}


{% block content %}
<div class='row'>
<div class='col-sm-6 col-sm-offset-3'>
<h1>Login</h1>
<form method="post" action="{% url 'django.contrib.auth.view.login' %}">
  {% csrf_token %}
  {{ form|crispy }}

  <input class='btn btn-block btn-primary' type="submit"
         value="{% trans 'LOGIN' %}" />
  <input type="hidden" name="next" value="{{ next }}" />
</form>
</div>

</div>
<hr/>
<div class='row'>
<div class='col-sm-6 col-sm-offset-3 text-align-center'>
<p>{% trans "Forgot password" %}? <a href="{% url 'auth_password_reset' %}">{% 
trans "Reset it" %}</a>!</p>
<p>{% trans "Not member" %}? <a href="{% url 'registration_register' %}">{% 
trans "Register" %}</a>!</p>
</div>
</div>

{% endblock %}




I have all the necessary apps and middleware installed and referenced in 
'thesite/settings.py'. I also have LOGIN_URL = '/login/' and LOGIN_REDIRECT_URL 
= '/theapp/', static files are referenced appropriately as well. Everything 
works fine when I don't have the login option available, so I'm pretty sure 
it's some error on my part with the templates. Any and all help is greatly 
appreciated!


Jason


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/23F547BAE064394F8249ECA5F8350F6628878622%40exmbt04.asurite.ad.asu.edu.
For more options, visit https://groups.google.com/d/optout.

Reply via email to