django templates 里面的url问题(原因未知)

点击查看代码
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'myapp1',
    'myapp2',
]

myapp1/url
from django.urls import path
from .views import runoob

urlpatterns = [
    path('runoob/',runoob,name='runoob'),
]

myapp2/url
from django.urls import path
from .views import runoob

urlpatterns = [
    path('runoob/',runoob,name='runoob'),
]

myapp1/views
from django.shortcuts import render
from django.urls import reverse

# Create your views here.


def runoob(request):
    context = {}
    context['hello'] = 'Hello World'
    url = reverse('runoob')
    print(url)
    return render(request,'runoob.html',context)


myapp2/views
from django.shortcuts import render
from django.urls import reverse

# Create your views here.


def runoob(request):
    context = {}
    context['hello'] = 'Hello World'
    # url = reverse('myapp2:runoob')
    # print(url)
    return render(request,'runoob.html',context)


templates
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>菜鸟教程</title>
</head>
<body>
    {{ hello }}
    {% url 'runoob' %}
    {% url 'runoob' %}
</body>
</html>

我访问myapp1/runoob/,得到的结果是/myapp2/runoob/?


posted @ 2025-07-28 09:21  夜说的世界  阅读(4)  评论(0)    收藏  举报