我正在尝试将数据插入到数据库中.Table已创建,但在插入数据时,它给出了错误,得到了一个意外的列名称(coursecode)关键字。但是在数据库列名称中是coursecode。 model.py的代码 来自django.db导入模型
# Create your models here.
class course(models.Model):
coursecode=models.CharField(max_length=10)
coursename=models.CharField(max_length=10)
startdate=models.CharField(max_length=10)
enddate=models.CharField(max_length=10)
image=models.CharField(max_length=10)
credits=models.CharField(max_length=10)
并且views.py是
from django.shortcuts import render
from django.shortcuts import render_to_response
from django.core.files.base import File
from course.models import course
from django.db.models import Q
from django.core.context_processors import csrf
# Create your views here.
def course(request):
if(request.method == 'POST'):
course_id1 = request.POST.get('coursecode', '')
course_name1 = request.POST.get('coursename', '')
credits1 = request.POST.get('creditwa', '')
end_date1=request.POST.get('enddate', '')
start_date1=request.POST.get('startdate', '')
image1=request.FILES.get('image','')
image2=request.FILES.get('image').name
course_data=course(coursecode=course_id1,coursename=course_name1,startdate=start_date1,enddate=end_date1,image=image2,creditwa=credits1
)
course_data.save()
return render(request,'course.html',{'form':''})
traceback error
course() got an unexpected keyword argument 'coursecode'
Request Method: POST
Request URL:
Django Version: 1.6.1
Exception Type: TypeError
Exception Value:
course() got an unexpected keyword argument 'coursecode'
Exception Location: /home/vc/portal/course/views.py in course, line 23
Python Executable: /usr/bin/python
Python Version: 2.7.6
Python Path:
['/home/vc/portal',
'/usr/local/lib/python2.7/dist-packages/setuptools-7.0-py2.7.egg',
'/usr/local/lib/python2.7/dist-packages/django_socketio-0.3.9-py2.7.egg',
'/usr/local/lib/python2.7/dist-packages/sphinx_me-0.3-py2.7.egg',
'/usr/local/lib/python2.7/dist-packages/gevent_socketio-0.2.1-py2.7.egg',
'/usr/local/lib/python2.7/dist-packages/gevent_websocket-0.9.3-py2.7.egg',
'/usr/lib/python2.7',
'/usr/lib/python2.7/plat-x86_64-linux-gnu',
'/usr/lib/python2.7/lib-tk',
'/usr/lib/python2.7/lib-old',
'/usr/lib/python2.7/lib-dynload',
'/usr/local/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages/PILcompat',
'/usr/lib/python2.7/dist-packages/gtk-2.0',
'/usr/lib/pymodules/python2.7',
'/usr/lib/python2.7/dist-packages/ubuntu-sso-client']
Server time: Tue, 11 Nov 2014 14:09:09 +0000