Py学习  »  Django

Django通过url传递数据,而不是在url模式中查找页面

The Ultraempoleon • 3 年前 • 1604 次点击  

我试图通过url传递一个对象的id,但它无法找到该页面,即使在它尝试通过其模式时的路径

错误:

Using the URLconf defined in GroomingService.urls, Django tried these URL patterns, in this order:

admin/
[name='Home']
appointment-Maker/
account/
admin-home
view_appointment/<id>/
login/ [name='Login Page']
registration/ [name='Registration Page']
logout [name='Logout Page']
The current path, adminview_appointment/21/, didn’t match any of these.

美容服务。网址

#urls
urlpatterns = [
    path('admin/', admin.site.urls),
    path('', Home_view, name="Home"),
    path('appointment-Maker/', include('appointmentApp.urls')),
    path('account/', include('accountApp.urls')),
    path('admin-home', include('adminApp.urls')),
    path('view_appointment/<id>/', viewAppointment_view), #this is the page it is not finding


    path('login/', Login_view, name='Login Page'),
    path('registration/', Registration_view, name='Registration Page'),
    path('logout', Logout_view, name='Logout Page')
]

adminApp/视图。py视图

def viewAppointment_view(request, id):
    appointments = Appointment.objects.get(id = id)
    context = {
        'appointments' : appointments
    }
    return render(request, "admin_templates/viewappointment.html", context)

模板/管理员模板查看约会。html

{% extends 'base.html' %}

{% block content %}
<a>appointment view</a>
{% endblock %}

templates/admin_templates adminhome。html(通过此页面单击链接)

{% extends 'base.html' %}

{% block content %}
<a>this is the admin page</a>
<br>

{% for a in appointments %}
<a href="adminview_appointment/{{a.id}}/">Client name:{{a.client_dog_name}}</a><br> {% comment %} this is the link that is clicked {% endcomment %}
{% endfor %}


<br>
<a>find month</a>
<form method="POST">
    {% csrf_token %}
    {{ monthyear }}
    <button class="btn btn-primary" type="submit">click</buttom>
    </form>

{% endblock %}

如果我遗漏了什么,请告诉我,我在adminApp/URL上找到了路径。早些时候

urlpatterns = [
    path('', views.adminhome_view, name="Admin Home"),
]

但将其移动到了试图查找URL的位置。我不知道为什么这可能不起作用。

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/129000
文章 [ 1 ]  |  最新文章 3 年前