This is probably something really simple but for some reason I just can’t seem to do it.
I’m trying to output some data from a blog (app) that I have created. The blog is working fine and out putting the content in the model fields that I have created and outputting to the templates I have specified.
But when tryingn to output the information out to the homepage nothing is showing. I’m fairly new to django and I think I might be missing something.
Do I need to include something to pages that are outside of the app? or do I need to set up somethin in the urls file?
I hope this makes sense as I don’t think it’s anything to complicated but I just think I’m missing something!
Thanks.
CODE:
url(r'blog/(?P<slug>[-\w]+)/$', 'blog.views.blog', name="blog"),
url(r'blog/', 'blog.views.blog_index', name="blog_index"),
def blog_index(request):
blogs = Blog.objects.filter(active=True)
return render_to_response('blog/index.html', {
'blogs':blogs,
}, context_instance=RequestContext(request))
def blog(request, slug):
blog = get_object_or_404(Blog, active=True, slug=slug)
return render_to_response('blog/blog_post.html', {
'blog': blog
}, context_instance=RequestContext(request))
class Blog(TimeStampedActivate):
title = models.CharField(max_length=255, help_text="Can be anything up to 255 character")
slug = models.SlugField()
description = models.TextField(blank=True, help_text="Give a short description of the news post")
content = models.TextField(blank=True, help_text="This is the main content for the news post")
user = models.ForeignKey(User, related_name="blog")
def __unicode__(self):
return self.title
@models.permalink
def get_absolute_url(self):
return ('blog', (), {
'slug': self.slug
})
Are you saying that going to
mysite.com/blog/is displaying correctly, but you also want it to be the sites index page atmysite.com?If so, you need to add a new pattern to your projects
urls.pyfile, like so:url(r'^$', 'blog.views.blog_index')Doing this will make
mysite.com/blog/andmysite.comroute to the same view.