Why does my dead simple Django app keep crashing python on my mac 10.6.4?
views.py
from django.shortcuts import render_to_response
from django.shortcuts import get_object_or_404
from django.shortcuts import get_list_or_404
from django.template.context import RequestContext
from articles.models import Article
def index(request):
articles = get_list_or_404(Article)
return render_to_response(
'articles/index.html',
{"articles": articles},
context_instance=RequestContext(request),
mimetype="application/xhtml+xml")
def article(request, article_id):
article = get_object_or_404(Article, pk=article_id)
return render_to_response(
'articles/article.html',
{"article": article},
context_instance=RequestContext(request),
mimetype="application/xhtml+xml")
models
from django.db import models
from django.contrib.auth.models import User
import datetime
class Article(models.Model):
"""
Article model
"""
title = models.CharField(blank=True, max_length=200)
slug = models.SlugField()
body = models.TextField(blank=True)
created = models.DateTimeField(blank=True, default=datetime.datetime.now)
author = models.ForeignKey(User)
def __unicode__(self):
return "%s" % (self.title)
@property
def handle(self):
return self.slug
urls
from django.conf.urls.defaults import *
urlpatterns = patterns('',
url(
r'^$',
'articles.views.index',
name="articles_index"
),
url(
r'^article/(?P<article_id>\d*)$',
'articles.views.article',
name="article_view",
),
)
root urls
from django.conf.urls.defaults import *
from django.contrib import admin
admin.autodiscover()
from settings import PROJECT_ROOT
urlpatterns = patterns('',
(r'^admin/', include(admin.site.urls)),
)
urlpatterns += patterns('',
(r'^articles/', include('articles.urls')),
)
urlpatterns += patterns('',
(r'^site_media/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': PROJECT_ROOT + "/media"}),
)
Would you need to see more?
I had a theory that the word 'Article' might have conflicted with something, tho I tried renaming that to no avail.
This is supposed to be just a little 'play app' that I'm learning on. But now I'm quite stuck.
Running: python manage.py runserver_plus
http://127.0开发者_JAVA技巧.0.1:8000/admin (views work ok) http://127.0.0.1:8000/articles (crashes python everytime)
Quite a hair pulling exercise... help very much appreciated
edit
the error report:
http://dpaste.org/8Fzx/
Thank you!
Answer: self referencing template!
精彩评论