**Hi all i am creating a student login page and gettting the error below, and to my surprise the same code for adminlogin works perfect. I am new to django so kindly clear my doubts to reduce this types of errors in future. Thanks in advance **
ValueError at /studentlogin/
The view myapp.views.studentlogin didn't return an HttpResponse object. It returned None instead.
Request Method: GET
Request URL: http://localhost:8000/studentlogin/
Django Version: 5.0.4
Exception Type: ValueError
Exception Value:
The view myapp.views.studentlogin didn't return an HttpResponse object. It returned None instead.
Exception Location: C:UsersHardip GajjarAppDataLocalProgramsPythonPython312Libsite-packagesdjangocorehandlersbase.py, line 332, in check_response
Raised during: myapp.views.studentlogin
Python Executable: C:UsersHardip GajjarAppDataLocalProgramsPythonPython312python.exe
Python Version: 3.12.2
Python Path:
['E:\KantamEducation',
'E:\KantamEducation',
'C:\Program '
'Files\JetBrains\PyCharm2023.3\plugins\python\helpers\pycharm_display',
'C:\Users\Hardip '
'Gajjar\AppData\Local\Programs\Python\Python312\python312.zip',
'C:\Users\Hardip Gajjar\AppData\Local\Programs\Python\Python312\DLLs',
'C:\Users\Hardip Gajjar\AppData\Local\Programs\Python\Python312\Lib',
'C:\Users\Hardip Gajjar\AppData\Local\Programs\Python\Python312',
'C:\Users\Hardip '
'Gajjar\AppData\Local\Programs\Python\Python312\Lib\site-packages',
'C:\Program '
'Files\JetBrains\PyCharm2023.3\plugins\python\helpers\pycharm_matplotlib_backend']
Server time: Tue, 23 Apr 2024 11:56:21 +0530
my views.py code is as under,
def studentlogin(request):
if request.method == 'POST':
try:
user = Student.objects.get(
email=request.POST['email'],
password=request.POST['password']
)
request.session['email'] = user.email
request.session['fname'] = user.fname
return render(request, 'studentindex.html')
except:
msg = 'Invalid Email or Password'
return render(request, 'studentlogin.html',{'msg':msg})
and my student login HTML form code is as under,
{% extends 'header.html' %}
{% load static %}
{% block content %}
<!-- Admin Login Page Start -->
<section class="section admin" data-section="section6" >
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="section-heading">
<h2>Student Login</h2>
</div>
<div class="section-heading">
{% if msg %}
<b style="font-size: 15px;color: antiquewhite;">{{msg}}</b>
{% endif %}
</div>
</div>
<div class="col-md-6">
<form type="POST" method ="post" id="studentlogin" action="{% url 'studentlogin' %}">
{% csrf_token %}
<div class="row">
<div class="col-md-6">
<fieldset>
<input name="email" type="email" class="form-control" id="email" placeholder="Your Email" required="">
</fieldset>
</div>
<div class="col-md-6">
<fieldset>
<input name="password" type="password" class="form-control" id="password" placeholder="Enter Password" required="">
</fieldset>
</div>
<div class="col-md-12">
<fieldset>
<button type="submit" id="form-submit" class="button">Login</button>
</fieldset>
</div>
</div>
</form>
</div>
</div>
</div>
</section>
<!--Admin Login Page Ends-->
{% endblock %}
</body>
</html>
**i am new to django. please help me. Thanks
while same code for admin account works fine, please go through the views.py code for admin as under,**
def adminlogin(request):
if request.method == "POST":
try:
user = Creator.objects.get(
email=request.POST['email'],
password=request.POST['password']
)
request.session['email'] = user.email
request.session['fname'] = user.fname
return render(request, 'adminindex.html')
except:
msg = "Invalid Username And Password"
return render(request, 'adminlogin.html', {'msg': msg})
else:
return render(request, 'adminlogin.html')
**thanks **