简体   繁体   English

提交表单时如何在 Django 中创建动态 URL

[英]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.

相关问题 Django - 一个页面上有两个forms,提交任何一个表单时如何维护URL参数? - Django - Two forms on one page, how can I maintain URL parameters when either form is submitted? 在 Django python 中创建动态动作 URL 形式 - Create dynamic action URL form in Django python 如何将提交表单中的字段传递到 Django 中的 url? - How to pass field from submitted form into url in Django? Django - 提交时表单不保存 - Django - Form not saving when submitted 未提交表单时如何在Django中使用get方法处理表单元素 - How to handle form elements with get method in django when form in not submitted 如何在 python (apiview,django) 中创建动态 url? - how to create a dynamic url in python (apiview,django)? 如何在Django的反馈表单中包含Submitted_date和Submitted_by? - How to include submitted_date and submitted_by in a feedback form in Django? 在使用Django中传递给URL的值提交后,如何手动填写表单字段? - How to manually fill a form field after being submitted using a value passed to the URL in Django? Django-如何通知用户表单提交成功与否? - Django - how to notify the user that form was submitted successfully or not? 如何访问 django 表单的提交值? - How to access the submitted value of a django form?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM