question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

'HttpResponse' object has no attribute 'render'

See original GitHub issue

Hi there, Firstly, GREAT app and exactly what I had in mind with wagtail! Thank you.

Just found a small “bug” with the build management command when a content object returns an HttpResponse object that has already rendered

bakery/views/base.py

self.get(self.request).render().content

throws

AttributeError: 'HttpResponse' object has no attribute 'render'

The “fix” on my side was to

        resp = self.get(self.request)

        if hasattr(resp, 'render'):
            return resp.render().content
        elif hasattr(resp, 'content'):
            return resp.content
        else:
            raise Exception('Response has no content')

Which is a little ugly especially in the else case… but I was just wanting to “make it work” on my side.

settings

BAKERY_MULTISITE = True

BAKERY_VIEWS = (
    'wagtailbakery.views.AllPublishedPagesView',
)
BUILD_DIR = '/tmp/asset-manager-build/'

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
robmoormancommented, Apr 10, 2017

Just ran into this issue again with HttpResponseRedirect response objects. Probably you use render_to_response or render shortcuts in your Wagtail page. Will provide a fix for this!

0reactions
robmoormancommented, Apr 11, 2017

Master should now work fine!

Read more comments on GitHub >

github_iconTop Results From Across the Web

'HttpResponse' object has no attribute '_committed'
I am working with a Django project, where I am trying to render a pdf and save it in my database. my models.py...
Read more >
'HttpResponseRedirect' object has no attribute '_meta'
I have the following code in views.py class OrganisationAddView(CreateView): model = models.Organisation fields = ( 'full_name' ...
Read more >
'SafeText' object has no attribute 'status_code' - Google Groups
Try using render or render_to_response instead of render_to_string. A view needs to return and HttpResponse object, not a string.
Read more >
Responses - Django REST framework
Unlike regular HttpResponse objects, you do not instantiate Response objects with rendered content. Instead you pass in unrendered data, which may consist ...
Read more >
Python's urllib.request for HTTP Requests - Real Python
The code in the finally block first checks if the response object exists with is not None , and then closes it. That...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found