2014-03-07 39 views
0

我是新來的Python和我的代碼給了我一個語法錯誤,因此沒有運行,我爲人不能弄清楚什麼是語法可以請任何人指出了我嗎?Python的語法錯誤使用Django

當前使用Python 3.3。

我的代碼

from django.conf.urls import patterns, include, url 
from django.views.generic import ListView 
from blog.models import Post 

urlpatterns = patterns('', 
         url(r'^'), ListView.as_view(
           queryset = Post.objects.all().order_by("-date")[:10], 
           template_name = "blog.html")), 
) 

我的編譯器說的語法錯誤是在最後一行,其中)是

感謝

+0

你有一個逗號,然後最後右括號.. –

+0

刪除多餘)後url模式 –

回答

1

你有你的括號混合起來。它應該是:

urlpatterns = patterns('', 
    url(r'^', ListView.as_view(
      queryset = Post.objects.all().order_by("-date")[:10], 
      template_name = "blog.html")), 
    # more url patterns 
) 

ListView.as_view()結果應該是第二個參數url()通話。

+0

非常感謝你工作像一個魅力:)也感謝您的快速反應。 –