【问题标题】:How to include app urls to project urls in Django 1.8?如何在 Django 1.8 中将应用程序 url 包含到项目 url 中?
【发布时间】:2015-10-24 01:56:18
【问题描述】:

我现在刚开始使用 django,正在配置 url。我能够映射不同的 url,如 /posts、/posts/create 等。不知何故,我无法配置根 url,我不确定我在做什么错。这是我的配置:

urlpatterns = [
# Examples:
url(r'',homeViews.posts),
# url(r'^blog/', include('blog.urls')),
url(r'^posts/',homeViews.posts),
url(r'^createPost/',homeViews.createPost),
url(r'^createUser/',userViews.createUser),
url(r'^post/(?P<title>[a-z,A-Z]+)/$',homeViews.post),
]`

干杯!

【问题讨论】:

标签: python django url


【解决方案1】:

这是一个例子,我的朋友。

from django.conf.urls import include, url
from django.contrib import admin

urlpatterns = [
    url(r'^admin/', include(admin.site.urls)),
    url(r'^$', 'home.views.home',name='index'),
    url(r'^contactanos/$', 'home.views.contacto',name='contacto'),
    url(r'^post/$', 'home.views.blog',name='blog')  
]

【讨论】:

    猜你喜欢
    • 2020-03-17
    • 1970-01-01
    • 1970-01-01
    • 2015-12-13
    • 1970-01-01
    • 1970-01-01
    • 2017-11-19
    • 2016-09-23
    • 2021-05-15
    相关资源
    最近更新 更多