[英]How to create dynamic URL in Django when form is submitted
I am building a website in django where user search for student data by entering the roll number of the student.我正在 django 中建立一个网站,用户通过输入学生的卷号来搜索学生数据。 For example if user enters the roll number 001 in the form then student data should be fetch from database and Url should be https://www.studentdata.com/001
例如,如果用户在表格中输入卷号 001,则应从数据库中获取学生数据,Url 应为https://www.studentdata.com/001
Similarly if user enters roll number 003 then the url should be https://www.student.com/003 and so on.同样,如果用户输入卷号 003,则 url 应为https://www.student.com/003等等。
I want to build website where I need to show thousands of student data.我想建立一个需要显示数千个学生数据的网站。
It's basic, have you try to solve this one by yourself?这是基本的,你有没有尝试自己解决这个问题? Next time before asking question also show code.
下次问问题之前还要显示代码。 By the way I wrote few lines of code for you.
顺便说一句,我为你写了几行代码。
views.py视图.py
def student_detail(request, student_id):
try:
student = Student.objects.get(id=student_id)
except Student.DoesNotExist:
raise Http404("Student does not exist")
urls.py网址.py
path("student/<int:student_id>", views.student_detail, name="student_detail")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.