Python/Django URL
免责声明……这是一项任务! 有人能告诉我为什么我变得越来越坚强吗Python/Django URL,python,django,url,Python,Django,Url,免责声明……这是一项任务! 有人能告诉我为什么我变得越来越坚强吗 Page not found (404) Request Method: GET Request URL: http://127.0.0.1:8000/%7B%20%25%20url%20'detail'%20user%20%25%20%7D Using the URLconf defined in bobbdjango.urls, Django tried these URL patterns, in this order
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/%7B%20%25%20url%20'detail'%20user%20%25%20%7D
Using the URLconf defined in bobbdjango.urls, Django tried these URL patterns, in this order:
[name='home']
profile [name='profile']
user_detail/<str:user_id> [name='detail']
The current path, { % url 'detail' user % }, didn’t match any of these.
You’re seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.
我的型号
from django.db import models
class User(models.Model):
first_name=models.CharField(max_length=30)
last_name=models.CharField(max_length=30)
email=models.EmailField()
def __str__(self):
return '{} {}'.format(self.first_name, self.last_name)
试试这个:
<a href="{ % url 'detail' user.id % }">
但我认为你应该改变
'user_detail/<str:user_id>'
“用户详细信息/”
作为
“用户详细信息/”
您的模板URL应如下所示:非常感谢这一帮助谢谢您。
def home(request):
users = User.objects.all()
return render(request, 'home.html', {'users': users})
def userdetail(request,user_id):
user = User.objects.get(id=user_id)
return render(request, 'user_detail.html', {'user': user})
def profile(request):
return render(request, 'profile.html')
from django.db import models
class User(models.Model):
first_name=models.CharField(max_length=30)
last_name=models.CharField(max_length=30)
email=models.EmailField()
def __str__(self):
return '{} {}'.format(self.first_name, self.last_name)
<a href="{ % url 'detail' user.id % }">
'user_detail/<str:user_id>'
'user_detail/<int:user_id>'