将用户的输入从一个页面转移到另一个页面

您所在的位置:网站首页 html中class属性的btn 将用户的输入从一个页面转移到另一个页面

将用户的输入从一个页面转移到另一个页面

2023-03-20 15:16| 来源: 网络整理| 查看: 265

我正在做一个网站,让学生可以找到即将到来的课程学习课程。我是用Django和HTML做的。学生把他们的课程上传到网站上,在课程页面上显示为按钮(例如:CS 101 - CS入门)。当学生点击他们的课程(按钮)时,应该把他们带到一个显示该课程可用学习课程的页面。我被卡住了,因为我不知道如何根据点击的课程在下一个页面正确过滤可用的学习课程。是否有办法将课程信息存储为一个变量,这样当按钮被点击时,我就可以用这个变量来过滤结果?编辑:我已经做了这些修改,现在我得到了一个ValueError,太多价值,无法解压,预计2。 我几乎可以肯定,这是在我的视图中发生。

这里是显示用户课程的页面。

{% if courses_list %} {% for course in courses_list %} {{ course.subject }} {{ course.number}}-{{course.name}} {% endfor %} {% else %}

You have not added any courses yet!

{% endif %}

这里是我试图过滤学习课程列表的页面(它有一个字段course,是Courses模型的外键)。

Upcoming Study Sessions Back to My Courses Date/Time: {{ session.date }} Location: {{ session.location }}

对模板的看法。

def CourseSessionView(request, course_pk): course_wanted = Course.objects.get(id=course_pk) try: return Study.objects.filter(course=course_wanted) except: return messages.error(request, 'There are no upcoming study sessions at this time for the requested course.')

课程和会议的模式。

class Course(models.Model): SUBJECT_CHOICES = [ ('AAS', 'AAS') ] subject = models.CharField( max_length=4, choices=SUBJECT_CHOICES, default='') number = models.PositiveSmallIntegerField( validators=[MaxValueValidator(9999)], default=0) name = models.CharField(max_length=100, default='') roster = models.ManyToManyField( Student, blank=True, related_name="courses") # Use [Student object].courses.all() to see all of a student's courses def __str__(self): return f"{self.subject} {self.number} - {self.name}" class Study(models.Model): organizer = models.ForeignKey(Student, on_delete=models.CASCADE) date = models.DateTimeField() # Use [Student object].studies.all() to see all of a student's study sessions attendees = models.ManyToManyField(Student, related_name="studies") location = models.CharField(max_length=30) course = models.ForeignKey(Course, on_delete=models.CASCADE) def __str__(self): return f"{self.date} - {self.location}"

Url:

path('/sessions/', views.CourseSessionView, name='course-session')


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3