TonyMontana
TonyMontana

Reputation: 261

Url doesnt run the proper view in pinax project blog

poblem mentioned at the end.

so i installed pinax blog app and added to my installed app , migrated and set up all its dependencies. i then added it to the urlpatterns in my project :

urlpatterns = [
    path('admin/', admin.site.urls),
    url(r"^blog/", include("pinax.blog.urls", namespace="pinax_blog")),
    url(r"^ajax/images/", include("pinax.images.urls", namespace="pinax_images")),
]

the urpatterns in pinax.blog.urls are :

urlpatterns = [
    url(r"^$", BlogIndexView.as_view(), name="blog"),
    url(r"^section/(?P<section>[-\w]+)/$", SectionIndexView.as_view(), name="blog_section"),
    url(r"^post/(?P<post_pk>\d+)/$", StaffPostDetailView.as_view(), name="blog_post_pk"),
    url(r"^post/(?P<post_secret_key>\w+)/$", SecretKeyPostDetailView.as_view(), name="blog_post_secret"),
    url(r"^feed/(?P<section>[-\w]+)/(?P<feed_type>[-\w]+)/$", blog_feed, name="blog_feed"),

    # authoring
    url(r"^manage/posts/$", ManagePostList.as_view(), name="manage_post_list"),
    url(r"^manage/posts/create/$", ManageCreatePost.as_view(), name="manage_post_create"),
    url(r"^manage/posts/(?P<post_pk>\d+)/update/$", ManageUpdatePost.as_view(), name="manage_post_update"),
    url(r"^manage/posts/(?P<post_pk>\d+)/delete/$", ManageDeletePost.as_view(), name="manage_post_delete"),

    url(r"^ajax/markdown/preview/$", ajax_preview, name="ajax_preview")
]

the BlogIndexView:

class BlogIndexView(ListView):
    model = Post
    template_name = "pinax/blog/blog_list.html"
    search_parameter = "q"
    paginate_by = settings.PINAX_BLOG_PAGINATE_BY

    def get_current_section(self):
        return "all"

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        context.update({
            "current_section": self.get_current_section(),
            "search_term": self.search_term()
        })
        return context

    def search_term(self):
        return self.request.GET.get(self.search_parameter)

    def search(self, posts):
        q = self.search_term()
        if q:
            posts = posts.filter(
                Q(title__icontains=q) | Q(teaser_html__icontains=q) | Q(content_html__icontains=q)
            )
        return posts

    def get_queryset(self):
        blog = hookset.get_blog(**self.kwargs)
        qs = Post.objects.current().filter(blog=blog).select_related("section", "blog")
        return self.search(qs)

Question:

when i run sever and go to http://127.0.0.1:8000/blog/ the BlogIndexView should work according to first url pattern of pinax_blog's url pattern and the template_name = "pinax/blog/blog_list.html" should be loaded. but the template doesnt load a different template called site_base.html loads instead . any ideas why?

Upvotes: 1

Views: 122

Answers (2)

KingNonso
KingNonso

Reputation: 712

the template doesnt load a different template called site_base.html loads instead . any ideas why?

I guess the question here is answering why the template loads site_base.html and does not show anything. Now the answer, above is correct, but lemme help the frustration of the person asking, to gain more clarity.

This is because the site_base.html does not have any block that can be extended, hence nothing shows when it loads.

{# This template intentionally left blank to satisfy test suites. Your project should always provide a site_base.html itself. #}

So simply adding this block of code to site_base.html

{% block body %}{% endblock %}

will give you something visible to see, and that's all you need to do.

Upvotes: 0

mfonism
mfonism

Reputation: 573

blog_list.html extends blog_base.html which in turn extends site_base.html.

If you track site_base.html down (perhaps, in your virtual env) you'll find out it doesn't provide the blocks to be filled out by the templates that extend it. Rather, it contains the comment:

{# This template intentionally left blank to satisfy test suites. Your project should always provide a site_base.html itself. #}

So, you're to provide a site_base.html in your project, which will override the stub provided by pinax.

For starters, your site_base.html can provide the body block:

{% block body %}{% endblock %}

Save it in <your-app>/templates/site_base.html, and make sure to add your app to INSTALLED_APPS (in your project's settings.py) before pinax.blog so that the template loader discovers its templates before the ones they are to override in pinax-blog.

Upvotes: 2

Related Questions