Python Django视图只呈现一个页面,不会呈现其余页面
因此,我在macosx上使用django 1.8,在配置html时遇到问题,即当我尝试加载另一个页面时,除了一个设置为默认页面(索引是默认页面)之外,它只是刷新了我在url.py中设置的默认页面,我无法访问除此之外的任何其他页面,但在url栏中,我可以看到我正在访问正确的html文件,因为它这样说,但页面没有更改…以下是我的代码: app/url.py----------- 这些是我试图安装的所有页面 main url.py------------- 从应用程序导入视图Python Django视图只呈现一个页面,不会呈现其余页面,python,html,django,url,view,Python,Html,Django,Url,View,因此,我在macosx上使用django 1.8,在配置html时遇到问题,即当我尝试加载另一个页面时,除了一个设置为默认页面(索引是默认页面)之外,它只是刷新了我在url.py中设置的默认页面,我无法访问除此之外的任何其他页面,但在url栏中,我可以看到我正在访问正确的html文件,因为它这样说,但页面没有更改…以下是我的代码: app/url.py----------- 这些是我试图安装的所有页面 main url.py------------- 从应用程序导入视图 urlpatterns
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'^',include('app.urls')),
]
这是我的观点-----------
您需要$来结束字符串。在你的情况下,他把一切都联系起来,从一切开始
url(r'^$', views.index, name='index'),
您可以使用views.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",{})
您需要$来结束字符串。在你的情况下,他把一切都联系起来,从一切开始
url(r'^$', views.index, name='index'),
您可以使用views.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",{})
不清楚发生了什么。如果您在浏览器上键入其他url,您可以访问任何其他url吗?您描述的行为只会发生在“关于”的情况下。在本代码中,您可以访问“联系人”、“项目”和“服务”。可以,但只有我设置为默认的索引或我设置为默认的任何其他索引,我才能访问,但当我尝试访问about.html时,url更改,但我从index.html获取代码@Walucas@MilanRasovic,如果你访问像
/contact/
这样的url会发生什么?@Sean Francis N.Ballais没有什么是一样的,我可以发送一个scrrenshot url更改,但我得到相同的index.html页面不清楚发生了什么。如果您在浏览器上键入其他url,您可以访问任何其他url吗?您描述的行为只会发生在“关于”的情况下。在本代码中,您可以访问“联系人”、“项目”和“服务”。可以,但只有我设置为默认的索引或我设置为默认的任何其他索引,我才能访问,但当我尝试访问about.html时,url更改,但我从index.html获取代码@Walucas@MilanRasovic,如果你访问像/contact/
这样的url会发生什么?@Sean Francis N.Ballais什么都不是,这是一样的,我可以发送一个scrrenshot url更改,但我得到相同的index.html页面很好,伙计!Django使用instabook.URL(main URL.py)中定义的URLconf尝试了以下URL模式,顺序如下:^admin/^contact/[name='contact']^projects/[name='projects']^services/[name='services']^$[name='index']^about/[name='about']^assets\/(?P.$当前路径about.html与这些模式都不匹配@Nico ZimmerI在我键入solution@SeanFrancisN.BallaisDo你试过了吗?在哪里@NicoZimmerGood接住了,伙计!Django使用instabook.URL(main URL.py)中定义的URLconf尝试了以下URL模式,顺序如下:^admin/^contact/[name='contact']^projects/[name='projects']^services/[name='services']^$[name='index']^about/[name='about']^assets\/(?P.$当前路径about.html与这些模式都不匹配@Nico ZimmerI在我键入solution@SeanFrancisN.BallaisDo你试过了吗?在哪里@尼科齐默