urls_js should not return HttpResponse#31
Conversation
|
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. |
|
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 django-js-reverse/tests/test_urls.py Line 21 in cdd25d2 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. |
|
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. |
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_inlinetemplate 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.