Python 嗨,我对django应用程序有问题。我确实希望使用以下url为用户创建个性化页面:url/user/id。但是有些东西不';行不通
我是编程界的新手,这是我的第一个真正的项目。通常我只是坐着思考解决问题,直到我的大脑烧坏。但这次我真的累坏了。也许很容易,但我真的没有找到解决办法 url.pyPython 嗨,我对django应用程序有问题。我确实希望使用以下url为用户创建个性化页面:url/user/id。但是有些东西不';行不通,python,django,Python,Django,我是编程界的新手,这是我的第一个真正的项目。通常我只是坐着思考解决问题,直到我的大脑烧坏。但这次我真的累坏了。也许很容易,但我真的没有找到解决办法 url.py from django.urls import path from . import views urlpatterns = [ path('profilo/<int:my_id>/', views.profilo, name='profilo') ] def profilo(request, my_id):
from django.urls import path
from . import views
urlpatterns = [
path('profilo/<int:my_id>/', views.profilo, name='profilo')
]
def profilo(request, my_id):
users = User.objects.get(id=my_id)
contex = {
"user": users
}
return render(request, 'profilo/profilo.html', contex)
base.html
{% load static %}
<html>
<head>
<title>Django Boyz blog</title>
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">
<link href='//fonts.googleapis.com/css?family=Lobster&subset=latin,latin-ext' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="{% static 'css/blog.css' %}">
</head>
<body>
<div class="page-header">
{% if user.is_authenticated %}
<a href="{% url 'post_new' %}" class="top-menu"><span class="glyphicon glyphicon-plus"></span></a>
<p class="top-menu">Ciao {{ user.username }} <small>(<a href="{% url 'logout' %}">Log out</a>)</small></p>
<a href="{% url 'profilo' User.id %}" class="top-menu"><span class="glyphicon glyphicon-user"></span></a>
{% if user.is_superuser %}
<a href="{% url 'numeroposts' %}" class="top-menu"><span class="glyphicon glyphicon-inbox"></span></a>
{% endif %}
{% else %}
<a href="{% url 'login' %}" class="top-menu"><span class="glyphicon glyphicon-lock"></span></a>
{% endif %}
<h1><a href="/">Django Boyz Blog</a></h1>
</div>
<div class="content container">
<div class="row">
<div class="col-md-8">
{% block content %}
{% endblock %}
</div>
</div>
</div>
</body>
</html>
{%load static%}
Django Boyz博客
{%if user.u经过身份验证%}
Ciao{{{user.username}}()
{%if user.is_superuser%}
{%endif%}
{%else%}
{%endif%}
{%block content%}
{%endblock%}
错误是:NoReverseMatch位于/
未找到参数为“(“”,)”的“profilo”的反转。尝试了1个模式:['profilo/(?P[0-9]+)/$']
感谢您在这一行:
<a href="{% url 'profilo' User.id %}" class="top-menu"><span class="glyphicon glyphicon-user"></span></a>
错误是否指定了错误的位置?如果是这样,请告诉我您访问的URL是什么导致此错误的?这不是因为
User.id
中的大写U吗?
<a href="{% url 'profilo' user.id %}" class="top-menu"><span class="glyphicon glyphicon-user"></span></a>