This is quite an open ended question, and touches on the subject of asset
pipelines.

This also touches on the whole debate around how JS applications should be
developed, libraries such as Ansible and Backbone may impact your
style/preference.

The closest library I've seen so far is django-pipeline, but it doesn't
have support for requirejs, there was also another discussion relating to
this topic [1].

For example, the rules of decoupling still apply, if the JS is not linked
to the site HTML in anyway (e.g. REST API) then you would ideally keep this
in a separate repo and use whatever asset pipeline suited you best. However
if your JS is closely coupled to your site HTML, then this would probably
stay inside your Django static.

It really depends on how complex your JS application is, for simple
requirements django-pipeline will do just fine. The best advice I can give
would be to research all the different options, and decide which is best
for your specific use case and tastes.

Hope this helps

Cal

[1] https://groups.google.com/forum/#!topic/requirejs/gDczhOVuYdc


On Wed, Jun 11, 2014 at 4:59 PM, César García Tapia <ta...@openshine.com>
wrote:

> Not really. I'm not looking for an answer to a specific question. I'm just
> looking for a "good practices manual" on writing and deploying javascript
> in a django environment.
>
>
>
> El miércoles, 11 de junio de 2014 17:41:45 UTC+2, Cal Leeming [Simplicity
> Media Ltd] escribió:
>>
>> Have a look at how Stripe do it [1].
>>
>> <script type="text/javascript" src="https://js.stripe.com/v2/";></script>
>> Stripe.setPublishableKey('YOUR_PUBLISHABLE_KEY');
>>
>> I think this is what you're asking for (if I've understood your question
>> correctly).
>>
>> Cal
>>
>> [1] https://stripe.com/docs/stripe.js
>>
>>
>>
>> On Wed, Jun 11, 2014 at 4:22 PM, César García Tapia <ta...@openshine.com>
>> wrote:
>>
>>> Hi.
>>>
>>> Probably this is an old subject, and it's been argued lots of times, but
>>> I guess I need some help to find the right resources.
>>>
>>> When building a real-world django application, you need javascript. Lots
>>> of it. Making JS talk to django is more or less easy: $.ajax(),
>>> django-rest-framework, and you're done. The problem comes when you need
>>> Django talking to JS. You need this variable initialized with some View
>>> context value, or init the i18n of that plugin with the {{ LANGUAGE_CODE
>>> }}, or whatever. There are a thousand cases that are on everybody's mind.
>>>
>>> The obvious way is to add a <script> tag in your template, and mix JS
>>> with django templates. Some examples:
>>>
>>>    var user = {{ user.id }};
>>>
>>>    $('{{ form.my_field.id_for_label}}').init_plugin();
>>>
>>>    var error_message = "{% trans 'You have a problem' %}";
>>>
>>>    var url = "{% url 'some:django:url' %}"
>>>
>>>    {% for item in some_context_variable %}
>>>       do_something();
>>>    {% endfor %}
>>>
>>> You get the idea. But it looks like a terrible anti-pattern. You can't
>>> reuse the JS code between templates, you can't consolidate all the JS
>>> in one big cacheable file, you can't minimize the JS code, you can't just
>>> serve the files as static content from a CDN...
>>>
>>> Is there any recommended way of approaching this kind of problems? It
>>> seems like a very obvious deployment-production subject to me, but I can't
>>> find any good practices documentation on this.
>>>
>>> Thank you!
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to django-users...@googlegroups.com.
>>> To post to this group, send email to django...@googlegroups.com.
>>>
>>> Visit this group at http://groups.google.com/group/django-users.
>>> To view this discussion on the web visit https://groups.google.com/d/
>>> msgid/django-users/fd031ae8-683c-4750-91b7-bdf56e966262%
>>> 40googlegroups.com
>>> <https://groups.google.com/d/msgid/django-users/fd031ae8-683c-4750-91b7-bdf56e966262%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/eccb5023-ddb9-49de-bca1-60af2c49498f%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/eccb5023-ddb9-49de-bca1-60af2c49498f%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAHKQagHZCY8q385tgoY1fz%3D07EQv8UuzvtTCqzgESqnAjXUPuQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to