Skip to content

urls_js should not return HttpResponse#31

Closed
coredumperror wants to merge 1 commit into
ierror:developfrom
coredumperror:develop
Closed

urls_js should not return HttpResponse#31
coredumperror wants to merge 1 commit into
ierror:developfrom
coredumperror:develop

Conversation

@coredumperror
Copy link
Copy Markdown
Contributor

From what I can tell, urls_js is supposed to return pure javascript text. But when passed a request object, it returns that text wrapped in an HttpResponse, which unnecessarily adds "Content-type: application/javascript" at the beginning of the output. This breaks the js_reverse_inline template tag, because "Content-type: application/javascript" is not valid javascript code.

This plugin is super awesome, so I hope you can incorporate this fix and get it pushed out to PyPI asap, so others won't run into the same problem that I did.

@coredumperror
Copy link
Copy Markdown
Contributor Author

Those tests failing is apparently a problem with the tests, rather than the change I made. The only places that the function I changed is called expect it to return plaintext, but the tests are apparently expecting an HttpResponse object for some reason.

@ierror
Copy link
Copy Markdown
Owner

ierror commented Aug 4, 2015

Sorry for the late reply and thank you for the contribution. The test fails because django_js_reverse.views.urls_js can be used as a view (returns a request object) see

url(r'^jsreverse/$', 'django_js_reverse.views.urls_js', name='js_reverse'),

Does the fix #27 solves your problem?

ATM I’m mixing the view-functionality and js-generation what’s not a good idea. I'll refactor the code to make this more clear.

@coredumperror
Copy link
Copy Markdown
Contributor Author

Yes, it appears that version 0.6.0 fixes the problem! Thank you!

I do agree, however, that you should refactor the code to separate the view functionality from the JS generation functionality. Having the view code call a separate function that generates the JS would be ideal. Then you could have the template tag call code that same generate function, and it wouldn't need to interact with the view code at all.

@ierror ierror closed this Aug 4, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants