我正在开发一个应用程序,用户将在其中提交一个值,我想在提交时隐藏包含表单的 div 并显示一个包含结果的 div。目标是让他们提交表单并显示不同的隐藏 div。我在使用 Django 代码或 Javascript 时做错了什么?
视图.py
from django.shortcuts import render
from .models import VintageMac
from .forms import VintageMacForm
def home(request):
if request.method == "POST":
form = VintageMacForm(request.POST)
if form.is_valid():
form.save()
form = VintageMacForm()
else:
form = VintageMacForm()
return render(request, 'hmwypapp/index.html', {'form': form})
网址.py
from django.urls import path
from . import views
urlpatterns = [
path('', views.home, name='home'),
]
模型.py
from django.conf import settings
from django.db import models
from django.utils import timezone
from django import forms
class VintageMac(models.Model):
price = models.IntegerField()
def publish(self):
self.save()
def __str__(self):
return '%s' % (self.price)
表格.py
from django import forms
from .models import VintageMac
class VintageMacForm(forms.ModelForm):
class Meta:
model = VintageMac
fields = ('price',)
qq_花开花谢_0
蓝山帝景
相关分类