点击查看代码
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/?