gpt4 book ai didi

django - 卡在 "Practical Django Projects"

转载 作者:行者123 更新时间:2023-12-04 06:32:25 25 4
gpt4 key购买 nike

本教程出现另一个错误。我应该放弃并转向另一个吗? …
无论如何..这里是:

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')),
)

最佳答案

在您的主 urls.py你有:

from coltrane.models. import Entry

将其更改为:
from coltrane.models import Entry

这将解决这个问题。 :D

关于django - 卡在 "Practical Django Projects",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5246847/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com