【问题标题】:how to set the index page in django like http://127.0.0.1:8000/如何在 django 中设置索引页面,如 http://127.0.0.1:8000/
【发布时间】:2014-04-11 11:23:16
【问题描述】:

我已经创建了一个类似这种结构的小项目..

|-我的网站
|-民意调查
|---静态
|-----民意调查
|-------css
|---------图片
|-------图片
|-------js
|---模板
|-----民意调查
|-模板
|---管理员
在民意调查中是应用程序,现在我使用此 url http://127.0.0.1:8000/polls/
获得输出 在主文件夹中,即 urls.py 中的 mysite 文件夹中,我有这样的代码..
urlpatterns = patterns('',
    url(r'^polls/',include('polls.urls',namespace="polls")),
    url(r'^admin/', include(admin.site.urls)),

现在在 urls.py 的 polls 文件夹中是..

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

现在我想获取像主网站地址这样的页面。http://127.0.0.1:8000/
如何获得?
谢谢。

【问题讨论】:

  • 当你尝试运行它时你的观察结果是什么?

标签: python django


【解决方案1】:

你能改变你这里的东西吗

url(r'^polls/',include('polls.urls',namespace="polls")),   

url(r'^', include('polls.urls', namespace="polls")),

现在原因是这样的: Django urls 使用正则表达式。在您的示例中,您告诉 django 捕获您的民意调查应用程序,从 localhost:8000/polls/

的 url 开始

了解更多:https://docs.djangoproject.com/en/dev/topics/http/urls/

即使在你的根项目 urls.py 中,你也有这个:

# Examples:
    # url(r'^$', 'Toolkit.views.home', name='home'), #this will match url of the type localhost:8000
    # url(r'^blog/', include('blog.urls')), # this will match url of the type localhost:8000/blog/

只要看起来敏锐!

【讨论】:

  • 是的,谢谢,我完全忘记了主要的 urls.py 并且盲目地遵循了教程。
猜你喜欢
  • 2019-06-04
  • 1970-01-01
  • 2020-10-25
  • 1970-01-01
  • 2011-04-22
  • 2019-05-22
  • 2015-01-18
  • 2021-11-13
  • 1970-01-01
相关资源
最近更新 更多