2

运行命令后,./manage.py runserver我收到以下错误。我知道这肯定与 Urls.py 有关(r'^$',views.main_page),,但似乎无法弄清楚需要更改什么......有什么建议吗?

网址.py

from django.conf.urls import patterns, include, url
from django.contrib import admin
from content import views

admin.autodiscover()

urlpatterns = patterns('',
# Examples:
# url(r'^$', 'crosstalk.views.home', name='home'),
# url(r'^crosstalk/', include('crosstalk.foo.urls')),

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

# Uncomment the next line to enable the admin:
(r'^$',views.main_page),
(r'^admin/', include(admin.site.urls)),
(r'^js/(?P<path>.*)$', 'django.views.static.serve', {'document_root': 'templates/js'}),
(r"^(\d+)/$", "post"),
)

模型.py

from django.db import models
from datetime   import datetime

class Cover(models.Model):  
title = models.CharField(max_length=200)
slug = models.SlugField(unique=True)
text = models.TextField()
posts = models.ManyToManyField('Post')
def __unicode__(self):
    return self.title

class Post(models.Model):  
title = models.CharField(max_length=200)
slug = models.SlugField(unique=True)
date = models.DateTimeField(default=datetime.now)
text = models.TextField()

def __unicode__(self):
    return self.title
4

2 回答 2

1

你没有main_pageviews.py. 这样做,包括适当的处理,它应该工作。

它应该看起来像这样:

def main_page(request):
    # view stuff goes here
    return something
于 2012-09-14T17:33:12.917 回答
0

检查你main_pageviews.py. 更好的方法是将其放在引号中

(r'^$','content.views.main_page')

假设这content是您的应用名称。

于 2012-09-14T17:31:25.773 回答