简体   繁体   中英

Django Shows Page Source Instead Of My Webpage

I have found that when passing context and a title into my views it causes the page to only show its html source code instead of the actual frontend graphics. If i remove the title being passed in then it works again but i do want to have the title passed in so is there any way to have this work?

Views

def myPosts(request):

    context = {
        'products': Post.objects.all()
    }

    return render(request, 'create/my_posts.html', context, {'title_page': 'My Posts'})

class PostListView(ListView):
    model = Post
    template_name = 'my_posts.html'
    context_object_name = 'products'

when you are passing context yo can do something like this context = { 'products': Post.objects.all(), 'title_page': 'My Posts' } and finally pass return render(request, 'create/my_posts.html', context)

In the front end, you can use it as context.title_page

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM