python - Django View 只渲染一页,不会渲染其余页面

标签 python html django url view

所以我在 macosx 上使用 django 1.8,并且在配置 html 时遇到问题,即当我尝试加载除默认设置的页面(索引是默认页面)之外的另一页面时,它只是刷新我的默认页面在 urls.py 中设置,我无法访问除该页面之外的任何其他页面,但在网址栏中我可以看到我正在访问正确的 html 文件,因为它这么说,但页面没有改变......这是我的代码:

app/urls.py------------

urlpatterns = [
    url(r'^contact/', views.contact, name='contact'),
    url(r'^projects/', views.projects, name='projects'),
    url(r'^services/', views.services, name='services'),
    url(r'^', views.index, name='index'),
    url(r'^about/', views.about, name='about'),

这些是我尝试安装的所有页面 主urls.py------------- 从应用程序导入 View

urlpatterns = [
    url(r'^admin/', include(admin.site.urls)),
    url(r'^',include('app.urls')),

]

这是我的观点.py------------

def contact(request):
    return render(request, 'app/template/contact.html',{})

def about(request):
    return render(request, 'app/template/about.html',{})

def projects(request):
    return render(request, 'app/template/projects.html',{})

def services(request):
    return render(request, 'app/template/services.html',{})

def index(request):
    return render(request, "app/template/index.html",{})

最佳答案

https://docs.djangoproject.com/en/1.8/intro/tutorial03/

您需要 $ 来结束字符串。在你的情况下,他链接了所有以 all 开头的内容。

url(r'^$', views.index, name='index'),

您的观点.py:

def contact(request):
    return render(request, 'app/contact.html',{})

def about(request):
    return render(request, 'app/about.html',{})

def projects(request):
    return render(request, 'app/projects.html',{})

def services(request):
    return render(request, 'app/services.html',{})

def index(request):
    return render(request, "app/index.html",{})

关于python - Django View 只渲染一页,不会渲染其余页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53558037/

相关文章:

Python - 基本切片与扩展切片

javascript - 合并选择框选择值

Javascript 不适用于 Django 模板继承

python - django.core.exceptions.FieldError : Local field 'email' in class 'User' clashes with field of similar name from base class 'AbstractUser'

Python 制表

python - Django模型.参数

python - 如何使用 python 在一个 Elasticsearch 查询中进行范围和匹配查询?

javascript - 如何将信息从 WPF 应用程序传递到 HTML 页面

javascript - 将html文件添加到div标签jquery

django - 如何获取模板中当前应用程序的名称?