2011-11-19 184 views
0

基本上,我使用Django/Python編寫博客軟件。目前,我有以下文件關於Django的問題urls.py

urls.py:

from django.conf.urls.defaults import * 

from django.contrib import admin 
admin.autodiscover() 

urlpatterns = patterns('', 
    # Example: 
    # (r'^sovietware/', include('sovietware.foo.urls')), 

    # Uncomment the admin/doc line below to enable admin documentation: 
    # (r'^admin/doc/', include('django.contrib.admindocs.urls')), 

    (r'^', include('sovietware.blog.urls')), 
    (r'^comments/', include('django.contrib.comments.urls')), 
    (r'^admin/', include(admin.site.urls)), 
) 

博客/ urls.py:

from django.conf.urls.defaults import * 
from models import Post 

queryset = {'queryset': Post.objects.order_by('-pub_date')} 
urlpatterns = patterns('django.views.generic.list_detail', 
    url('^$', 'object_list', queryset, name='posts'), 
    url('^(?P<object_id>\d+)/$', 'object_detail', queryset, name='post'), 
) 

我的問題是......目前,這意味着當我在/和我點擊一個博客條目的標題鏈接,我被重定向到/ 1/...我希望它重定向到/ blog/1 /而 - 這是我需要在urls.py中編輯的東西嗎?如果是這樣,我需要添加什麼?

+0

這取決於很多不僅僅是'urls.py'。 –

回答

0

在您的主要urls.py中,將urlpatterns重命名爲base_urlpatterns。然後,在底部,添加以下內容:

urlpatterns = patterns('', 
    '^', include(base_urlpatterns), # iff you wish to maintain the un-prefixed URLs too 
    '^your_prefix/', include(base_urlpatterns), 
) 

信用:lallulli, commenting on djangosnippets

1

我不知道你的/ URL儘可能數據返回什麼,但如果你想所有的模式在您的博客應用開始在URL「博客」,你可以在你做的包括添加的圖案在你的根urls.py:

(r'^blog/', include('sovietware.blog.urls')),