Hi,
Its a shame that I am not able to resolve this simple issue. Explanation as 
below
Once the user login, he/she will be rendered to a page called (chitrr.html). 
This I have mentioned as a "return redirect('chitrr')". But when I login, it is 
giving "NoReverseMatch" error. 
It's ironic that everything was working before. But I don't know what changed, 
things went south. 
views.py-----------def login_user(request):
    if request.method == 'POST':
        username = request.POST['username']
        password = request.POST['password']
        user = authenticate(request, username=username, password=password)
        if user is not None:
            login(request, user)
            messages.success(request, f'login success')
            return redirect('chitrr')
        else:
            messages.error(request, f'error while login, please try again')
            return redirect('login')
    else:
        return render(request, 'authenticate\\login.html', 
{})urls.py---------urlpatterns = [
    path("home/", home, name='home'),
    path("login/", login_user, name='login'),
    path("logout/", logout_user, name='logout'),
    path("register/", register_user, name='register'),
    path("profile1/", userProfileView, name='profile1'),
    path('summary/', getUserProfile.as_view(), name='summary'),  # drf
    path('comp/', GetUserData.as_view(), name='comp')
]chitrr.html--------------
{% extends 'base.html' %}
{% load crispy_forms_tags %}
{% load static %}
{% block content %}

<form method="post" enctype="multipart/form-data" action="">
    {% csrf_token %}
<div class="row" >
    <div class="col-6">
        {{form.Photo|as_crispy_field }}
    </div>

    <div class="col-6">
        {{form.dob|as_crispy_field }}
    </div>
</div>

<div class="row" >
    <div class="col-6">
        {{form.country|as_crispy_field }}
    </div>

    <div class="col-6">
        {{form.State|as_crispy_field }}
    </div>
</div>
    <div class="row" >
    <div class="col-6">
        {{form.District|as_crispy_field }}
    </div>

    <div class="col-6">
        {{form.phone|as_crispy_field }}
    </div>
</div>
    <button type="submit" class="btn btn-success">Save</button>
</form>
{% endblock %}login.html---------------
<!DOCTYPE html>
<html>

<head>
   <title>Login</title>
   <link rel="stylesheet" 
href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"; 
integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO"
 crossorigin="anonymous">
   <script 
src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js";></script>
   <link rel="stylesheet" 
href="https://use.fontawesome.com/releases/v5.6.1/css/all.css"; 
integrity="sha384-gfdkjb5BdAXd+lj+gudLWI+BXq4IuLW5IT+brZEZsLFm++aCMlF1V92rMkPaX4PP"
 crossorigin="anonymous">


   <style>
      body,
      html {
         margin: 0;
         padding: 0;
         height: 100%;
         background: #7abecc !important;
      }
      .user_card {
         width: 350px;
         margin-top: auto;
         margin-bottom: auto;
         background: #74cfbf;
         position: relative;
         display: flex;
         justify-content: center;
         flex-direction: column;
         padding: 10px;
         box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 
0.19);
         -webkit-box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 
rgba(0, 0, 0, 0.19);
         -moz-box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 
0, 0, 0.19);
         border-radius: 5px;

      }

      .form_container {
         margin-top: 20px;
      }

      #form-title{
         color: #fff;

      }

      .login_btn {
         width: 100%;
         background: #33ccff !important;
         color: white !important;
      }
      .login_btn:focus {
         box-shadow: none !important;
         outline: 0px !important;
      }
      .login_container {
         padding: 0 2rem;
      }
      .input-group-text {
         background: #f7ba5b !important;
         color: white !important;
         border: 0 !important;
         border-radius: 0.25rem 0 0 0.25rem !important;
      }
      .input_user,
      .input_pass:focus {
         box-shadow: none !important;
         outline: 0px !important;
      }

      #messages{
         background-color: grey;
         color: #fff;
         padding: 10px;
         margin-top: 10px;
      }
   </style>

</head>
<body>
   <div class="container h-100">
      <div class="d-flex justify-content-center h-100">
         <div class="user_card">
            <div class="d-flex justify-content-center">


               <h3 id="form-title">LOGIN</h3>
            </div>
            <div class="d-flex justify-content-center form_container">
               <form method="POST" action="">
                  {% csrf_token %}
                  <div class="input-group mb-3">
                     <div class="input-group-append">
                        <span class="input-group-text"><i class="fas 
fa-user"></i></span>
                     </div>
                     <input type="text" name="username" 
placeholder="Username..." class="form-control">
                  </div>
                  <div class="input-group mb-2">
                     <div class="input-group-append">
                        <span class="input-group-text"><i class="fas 
fa-key"></i></span>
                     </div>
                        <input type="password" name="password" 
placeholder="Password..." class="form-control" >
                  </div>

                     <div class="d-flex justify-content-center mt-3 
login_container">
                        <input class="btn login_btn" type="submit" 
value="Login">
                         </div>
               </form>

            </div>
                {{ form.errors }}
            {% for msg in messages %}
            <p id="messages">{{ msg }}</p>
            {% endfor %}
            <div class="mt-4">
               <div class="d-flex justify-content-center links">
                  Don't have an account? <a href="{% url 'register' %}" 
class="ml-2">Sign Up</a>
               </div>

            </div>
         </div>
      </div>
   </div>
</body>

</html>Error:-------
NoReverseMatch at /login/
Reverse for 'chitrr' not found. 'chitrr' is not a valid view function or 
pattern name.
| Request Method: | POST |
| Request URL: | http://127.0.0.1:8000/login/ |
| Django Version: | 3.0.5 |
| Exception Type: | NoReverseMatch |
| Exception Value: | Reverse for 'chitrr' not found. 'chitrr' is not a valid 
view function or pattern name. |
| Exception Location: | C:\Python38\lib\site-packages\django\urls\resolvers.py 
in _reverse_with_prefix, line 677 |
| Python Executable: | C:\Python38\python.exe |
| Python Version: | 3.8.2 |
| Python Path: | ['C:\\Users\\anshu\\djago-project\\SkoolSkill',
 'C:\\Python38\\python38.zip',
 'C:\\Python38\\DLLs',
 'C:\\Python38\\lib',
 'C:\\Python38',
 'C:\\Python38\\lib\\site-packages'] |
| Server time: | Tue, 28 Apr 2020 13:14:19 +0000 |

Full trace logs:: dpaste: 019R3X8: NoReverseMatch at /login/, by Django

| 
| 
|  | 
dpaste: 019R3X8: NoReverseMatch at /login/, by Django


 |

 |

 |



Thank you,Sam

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1691891901.1043679.1588087538353%40mail.yahoo.com.

Reply via email to