Tuesday, May 30, 2017

Re: DJANGO 1.1 dynamic url on static javascript

Everything looking like {% %} or {{ }} are template tag. Your js file
are not processed by the templating engine so they can be served
really fast directly by your web server and not by django which is a
lot slower.

One solution would be to but the url in your html file. Add a <script>
tag sonewhere with `URL = { validate_username: "{% url
"validate_username" %}" }; `

2017-05-30 18:16 GMT+02:00 lenin david <lenin.martinez123@gmail.com>:
> ## Context
> I am adding a static javascript file to my **ModelForm** on this way
>
> forms.py
>
> <!-- language: lang-python -->
>
> class SomeForm(forms.ModelForm):
>
> class Media:
> js = ('some-javascript.js',)
>
> ## Problem
>
> On this javascript I need send a GET request to a rest endpoint hosted on
> same application using jquery, but i need the Server domain or a function to
> construct my url
>
> some-javascript.js,
>
> <!-- language: lang-javascript -->
>
> django.jQuery.get('{% url "validate_username" %}')
>
>
> ## expect behavior
>
> If I could create my url with django I could send the request without
> problems, Thanks in advance
>
>
> I posted this question on: https://stackoverflow.com/posts/44266904/edit
>
> --
> 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+unsubscribe@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/99b1a2e3-879e-4395-98b4-52ba8d286bbc%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.



--

Cordialement, Ludovic Coues
+33 6 14 87 43 42

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAEuG%2BTZLFk9inMehpArHFQMwWru-qRbr6svZRJy1t37vUEimMA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment