我一直在尝试使用bu表单将登录信息提交到Django中的数据库,但不断收到我尝试修复的错误。在这里找到了类似的答案,但对我没有用。有人可以帮我吗
urls.py
from django.contrib import admin
from django.urls import path
#from customers.views import home_view
#from customers.views import design_view
from customers.views import CustomerForm
urlpatterns = [
#path('',home_view,name='home'),
path('for/',CustomerForm,name='form'),
#path('design/',design_view,name='design'),
path('admin/', admin.site.urls),
]
template / design.html
<h1>THIS IS ABOUT MY NAME</h1>
<form>{% csrf_token %}
{{ form.as_p }}
<input type="submit" name="" value="save">
</form>
forms.py
from django import forms
from .models import Login
class CustomerForm(forms.ModelForm):
class Meta:
model = Login
fields=['email','password']
views.py
from django.shortcuts import render
from django.http import HttpResponse
# Create your views here.
from .forms import CustomerForm
from .models import Login
def Login_view(request):
#return HttpResponse("<h1>this is the home page</h1>")
forme = CustomerForm(request.POST)
if forme.is_valid():
forme.save()
#log=Login.objects.get(id=1)
context={
'form':forme
}
return render(request,"more/design.html",context)
models.py
from django.db import models
# Create your models here.
class Login(models.Model):
email=models.EmailField(max_length=30)
password=models.CharField(max_length=30)
错误代码
Internal Server Error: /for/
Traceback (most recent call last):
File "C:\Users\Henry R\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
response = get_response(request)
File "C:\Users\Henry R\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\utils\deprecation.py", line 96, in __call__
response = self.process_response(request, response)
File "C:\Users\Henry R\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\middleware\clickjacking.py", line 26, in process_response
if response.get('X-Frame-Options') is not None:
AttributeError: 'CustomerForm' object has no attribute 'get'
[27/Nov/2019 01:09:29] "GET /for/ HTTP/1.1" 500 58312