ValueError

22 views
Skip to first unread message

Desh Deepak

unread,
Jul 10, 2019, 2:05:17 PM7/10/19
to django...@googlegroups.com
Hi, I want to insert some data in MysqlDatabase from the template (HTML file).
but, it shows error like this...

The view Naturalgreen.views.index didn't return an HttpResponse object. It returned None instead.
Request Method:GET
Request URL:http://127.0.0.1:8000/
Django Version:2.0
Exception Type:ValueError
Exception Value:

Python Version:3.7.3
Django Version: 2.0


(views.py)
from django.shortcuts import render
from django.http import HttpResponse
from Naturalgreen.models import signin


# Create your views here.

def index(request):
if request.method == 'POST':
if request.POST.get('username') and request.POST.get('password'):
POST = naturalgreen_signin()
POST.username = request.POST.get('username')
POST.password = request.POST.get('password')
post.save()
return HttpResponseRedirect(request, "index.html")
else:
return HttpResponse(request, 'home.html')


(models.py)

from django.db import models

# Create your models here.
class signin(models.Model):
username = models.CharField(max_length=200, blank=False)
password = models.CharField(max_length=150, blank=False)


class Meta:
db_table ="naturalgree_signin"


(index.html)
{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Natural Green</title>

</head>

<body>
<div>
<h2>Please Enter your Login Details !</h2>
<form method="POST" action="{% url 'home' %}" name="">
{% csrf_token %}
Username: <input type="text" name="username">
Password: <input type="text" name="password">
<button type="submit" value="naturalgreen_signin">Login</button>
</form>
</div>

</body>

</html>



thanks:
Desh Deepak 
+917011101001
deshde...@gmail.com

Jani Tiainen

unread,
Jul 10, 2019, 5:03:21 PM7/10/19
to django...@googlegroups.com
Hi.

Because indentation is broken it's hard to say exact problem location but in your view some code path doesn't return anything and thus you see error about returning None.

--
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...@googlegroups.com.
To post to this group, send email to django...@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/CAJ0m4xjVuP91YmjZ423UZfgiRoPtg3GvgsRgZR_KMc2vOgFXBQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

amin ghaemi

unread,
Jul 10, 2019, 8:32:00 PM7/10/19
to django...@googlegroups.com
hi
you must see tutorial of django Framework first and than start the work
please Search django auth users
django logins and sign up is automatic 

Reply all
Reply to author
Forward
0 new messages