我收到以下錯誤:如何(基數爲10無效字面INT():「ASDF」)插入sqlite的Django的數據
(invalid literal for int() with base 10: 'any thing'
我絕對新在Django和Python,我想通過Django的ORM插入數據表,但我不能和我一起努力解決它,但不同的錯誤來自不同的階段,請幫我解釋一下:
這是我的views.py:
from django.shortcuts import render
from django.http import HttpResponse, request, Http404, HttpResponseRedirect
from django.template import Context
from django.template.loader import get_template
from django.contrib.auth.models import User
from django.contrib.auth import logout
from .models import Signup
from django.shortcuts import render_to_response
import sqlite3
def first_page(request):
username = request.GET['txtname']
password = request.GET['txtpassword']
contact = request.GET['txtcontact']
address = request.GET['txtaddress']
# db = sqlite3.connect('mydatabase')
# cursor = db.cursor()
# cursor.execute('''INSERT INTO Signup(name, password, contact, address) VALUES (?,?,?,?)''', (username, password, contact, address))
signup = Signup(username, password, contact, address)
signup.save()
return render_to_response("first_page.html", {'name': username,
'password': password,
'contact': contact,
'address': address})
def sign_up(request):
return render_to_response("signup.html")
這裏是我的models.py
from django.db import models
class Signup(models.Model):
name = models.CharField(max_length=200)
password = models.CharField(max_length=50)
contact = models.IntegerField()
address = models.CharField(max_length=250)
這裏是我的sigup.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Sign Up Form</title>
</head>
<body>
<form action="." method="get">
<label for="txtname">Name</label>
<input type="text" id="txtname" name="txtname"/><br/><br/><br/>
<label for="txtpassword">Password</label>
<input type="password" id="txtpassword" name="txtpassword"/><br/><br/><br/>
<label for="txtcontact">Contact</label>
<input type="number" id="txtcontact" name="txtcontact"/><br/><br/><br/>
<label for="txtaddress">Address</label>
<input type="text" id="txtaddress" name="txtaddress"/><br/><br/><br/>
<input type="submit" id="btnsignup" name="btnsignup" value="Register">
</form>
</body>
</html>
這裏是我的urls.py
from django.conf.urls import url
from django.contrib import admin
from reg.views import *
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^first/', first_page),
url(r'^register$', sign_up),
url(r'^$', first_page),
]
請發佈錯誤的堆棧跟蹤。 – solarissmoke
另外,哪些操作和值導致錯誤?只用錯誤消息和大量代碼很難。 –