2011-03-09 64 views
2

本教程有另一個錯誤。我應該放棄並轉移到另一個? ... 反正..這裏有雲:卡住了「實用的Django項目」

Environment: 

Request Method: GET 
Request URL: http://127.0.0.1:8000/admin/ 
Django Version: 1.2.5 
Python Version: 2.5.4 
Installed Applications: 
['django.contrib.auth', 
'django.contrib.contenttypes', 
'django.contrib.sessions', 
'django.contrib.sites', 
'django.contrib.messages', 
'django.contrib.admin', 
'django.contrib.flatpages', 
'cms.search', 
'coltrane', 
'tagging'] 
Installed Middleware: 
('django.middleware.common.CommonMiddleware', 
'django.contrib.sessions.middleware.SessionMiddleware', 
'django.middleware.csrf.CsrfViewMiddleware', 
'django.contrib.auth.middleware.AuthenticationMiddleware', 
'django.contrib.messages.middleware.MessageMiddleware') 


Traceback: 
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/core/handlers/base.py" in get_response 
    91.       request.path_info) 
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/core/urlresolvers.py" in resolve 
    215.    for pattern in self.url_patterns: 
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/core/urlresolvers.py" in _get_url_patterns 
    244.   patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module) 
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/core/urlresolvers.py" in _get_urlconf_module 
    239.    self._urlconf_module = import_module(self.urlconf_name) 
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/utils/importlib.py" in import_module 
    35.  __import__(name) 

Exception Type: SyntaxError at /admin/ 
Exception Value: invalid syntax (urls.py, line 6) 

這裏的網址:

from django.conf.urls.defaults import * 

from coltrane.models import Entry 

entry_info_dict = { 
    'queryset': Entry.objects.all(), 
    'date_field': 'pub_date', 
} 

urlpatterns = patterns('django.views.generic.date_based', 
    (r'^$', 'archive_index', entry_info_dict, 'coltrane_entry_archive_index'), 

    (r'^(?P<year>\d{4})/$', 'archive_year', entry_info_dict, 'coltrane_entry_archive_year'), 

    (r'^(?P<year>\d{4})/(?P<month>\w{3})/$', 'archive_month', entry_info_dict, 'coltrane_entry_archive_month'), 

    (r'^(?P<year>\d{4})/(?P<month>\w{3})/(?P<day>\d{2})/$', 'archive_day', entry_info_dict, 'coltrane_entry_archive_day'), 

    (r'^(?P<year>\d{4})/(?P<month>\w{3})/(?P<day>\d{2})/(?P<slug>[-\w]+)/$', 'object_detail', entry_info_dict, 'coltrane_entry_detail'), 
) 

我猜的錯誤是entry_info_dict。任何幫助?提前致謝。

這裏的models.py:

import datetime 
from django.conf import settings 
from django.db import models 
from django.contrib.auth.models import User 
from tagging.fields import TagField 
from markdown import markdown 
import tagging 

class Category(models.Model): 
    title = models.CharField(max_length=250, help_text='Maximum 250 characters.') 
    slug = models.SlugField(help_text="Suggested value automatically generated from title. Must be unique.") 
    description = models.TextField() 

    class Meta: 
     ordering = ['title'] 
     verbose_name_plural = "Categories" 

    def __unicode__(self): 
     return self.title 

    @models.permalink 
    def get_absolute_url(self): 
     return ('coltrane_category_detail',(), { 'slug': self.slug }) 

class Entry(models.Model): 
    LIVE_STATUS = 1 
    DRAFT_STATUS = 2 
    HIDDEN_STATUS = 3 
    STATUS_CHOICES = (
     (LIVE_STATUS, 'Live'), 
     (DRAFT_STATUS, 'Draft'), 
     (HIDDEN_STATUS, 'Hidden'), 
    ) 

    # Core fields 
    title = models.CharField(max_length=250) 
    excerpt = models.TextField(blank=True) 
    body = models.TextField() 
    pub_date = models.DateTimeField(default=datetime.datetime.now) 

    # Metadata 
    author = models.ForeignKey(User) 
    enable_comments = models.BooleanField(default=True) 
    featured = models.BooleanField(default=False) 
    slug = models.SlugField(unique_for_date='pub_date') 
    status = models.IntegerField(choices=STATUS_CHOICES, default=LIVE_STATUS) 

    # Categorization 
    categories = models.ManyToManyField(Category) 
    tags = TagField() 

    # Fields to store generated HTML 
    excerpt_html = models.TextField(editable=False, blank=True) 
    body_html = models.TextField(editable=False, blank=True) 

    class Meta: 
     verbose_name_plural = "Entries" 
     ordering = ['-pub_date'] 

    def save(self, force_insert=False, force_update=False): 
     self.body_html = markdown(self.body) 
     if self.excerpt: 
      self.excerpt_html = markdown(self.excerpt) 
     super(Entry, self).save(force_insert, force_update) 

    def __unicode__(self): 
     return self.title 

    @models.permalink 
    def get_absolute_url(self): 
     return ('coltrane_entry_detail',(), { 'year': self.pub_date_strftime("%Y"), 'month': self.pub_date_strftime("%b").lower(), 'day': self.pub_date.strftime("%d"), 'slug': self.slug }) 

這裏的主urls.py

from django.conf.urls.defaults import * 
from django.contrib import admin 
import settings 
admin.autodiscover() 

from coltrane.models. import Entry 

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

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

    # Uncomment the next line to enable the admin: 
    (r'^admin/', include(admin.site.urls)), 
    (r'^search/$', 'cms.search.views.search'), 
    (r'tiny_mce/(?P<path>.*)$', 'django.views.static.serve', { 'document_root': '/Users/danielcorreia/Sites/tinymce/jscripts/tiny_mce' }), 
    (r'^weblog/', include('coltrane.urls')), 
    (r'', include('django.contrib.flatpages.urls')), 
) 
+0

你能粘貼你的models.py嗎? – 2011-03-09 14:26:34

+0

是的。希望有所幫助。 – danielcorreia 2011-03-09 14:27:41

+0

你的模特兒有一位「直播」經理? – 2011-03-09 14:23:17

回答

2

在你的主urls.py您有:

from coltrane.models. import Entry 

修改成:

from coltrane.models import Entry 

這將解決這個問題。 :D

+0

謝謝!!! =) – danielcorreia 2011-03-09 15:41:01

1

你的模型有一個 「活」 的經理嗎?

+0

不確定你的意思,但我粘貼models.py – danielcorreia 2011-03-09 14:28:14

+0

在entry_info_dict字典中,更改Entry.objects.all()的Entry.live.all()。 – 2011-03-09 14:29:13

+0

仍然出現同樣的錯誤。不知道我在哪裏得到live.all()錯誤。 – danielcorreia 2011-03-09 14:44:40