我正在尝试使用 js 的 onclick 事件在页面上生成动态内容,但控制台中出现错误“Uncaught SyntaxError: Unexpected identifier”
html
{% load static %}
<head>
<script type="text/javascript">
function myFunction() {
// document.getElementById("demo").innerHTML = "Paragraph changed.";
document.getElementById("demo").innerHTML = "{{ Malegender }}";
}
</script>
</head>
<body>
<div class="container mt-5">
<h1>Gender</h1>
<hr>
<h5>{{ mygender.as_p }}</h5>
<h1 id="demo">Hello</h1>
<div class="container">
<button type="submit" name="gender_submit" class="btn btn-success" onclick="myFunction()">Confirm</button>
</div>
</div>
</body>
视图.py
def Gender(request):
gender_selection = GenderForm()
male_detail = MaleForm()
Male = False
print("Value of male",Male)
if 'gender_submit' in request.POST:
male_detail = MaleForm(data=request.POST)
Male = True
print("Value of male d",Male)
print("Value of male a",Male)
return render(request, 'Gender.html',{"mygender":gender_selection,"Malegender":male_detail})
表格.py
class MaleForm(forms.ModelForm):
class Meta:
model = GenderModel
fields = ('genderMale','genderMale1','genderMale2','genderMale3','genderMale4')
模型.py
from django.db import models
from django.contrib.auth.models import User
from django.db.models.signals import post_save
from django.dispatch import receiver
# Create your models here.
class GenderModel(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
gender_choice=(('Male','Male'),('Female','Female'),)
gender = models.CharField(max_length=6,choices=gender_choice,null=True,)
genderMale = models.BooleanField(default=False)
genderMale1 = models.BooleanField(default=False)
genderMale2 = models.BooleanField(default=False)
genderMale3 = models.BooleanField(default=False)
genderMale4 = models.BooleanField(default=False)
当我单击按钮时,控制台上显示错误。当用户单击按钮时,我试图显示该内容
猛跑小猪
相关分类