I think to move the all javascript code from your templates to .js files,
you
must change the way your views are working.

I think your url and view are expecting some parameters, for this reason
the problem
with urls and his generation.

The case about the checkbox changing, can be resolved re-defining the view.
For instance:

# my view
def my_view(request):
    if request.method == 'POST' and 'data' in request.POST:
        # process data .....

# my urls
url(
        r'^test/whatever/$',
        'my_view',
        name='my_view',
    ),

So, the url definition no depends about some parameter and can be included
in the template as a data property that can be read from javascript file.
The ajax
post request can build in dynamic way.


On Sat, Jan 26, 2013 at 10:52 AM, Jason <1jason.whatf...@gmail.com> wrote:

> Hi,
>
> Thanks for your response.
>
> A lot of the content is generated by javascript, including the elements
> which fire the javascript functions.  For example there is a method which
> writes a checkbox to the DOM - the value of which is given by an AJAX
> query. When it is checked/unchecked it fires a js function sending the
> value to the server (at some url given by a template variable). Because the
> checkbox is itself produced by a function within the external/static
> myjavascript.js file I experience the same problem attributing a data
> property as you suggest.
>
> On Saturday, January 26, 2013 2:50:44 PM UTC, juanblo wrote:
>
>> Hi,
>>
>> You can use data properties, for example:
>>
>> # Template
>>
>> <div id="my_container" data-url="{{ url_endpoints param }}">
>> </div>
>>
>> # Javascript
>>
>> $('#address').editable({
>>     type: 'text',
>>     url: $('#my_container').data('url')**,
>>     ......
>> });
>>
>> Hope this helps,
>>
>> On Sat, Jan 26, 2013 at 8:54 AM, Jason <1jason....@gmail.com> wrote:
>>
>>> Hi there.
>>>
>>>
>>> I am moving some javascript from my html to an external js file. At present 
>>> however, whenever my pages are rendered I use variable names to give url 
>>> endpoints, for example:
>>>
>>>
>>>     $('#address').editable(
>>>         {
>>>             type: 'text',
>>>             send : "always",
>>>             url: '{{ url_endpoints.logged_in_**change_address }}', // the 
>>> variable value becomes something like /au/change_address
>>>             title: 'Enter kindle address',
>>>             success: function() {
>>>                 window.location.reload();
>>>             }
>>>         }
>>>     );
>>>
>>>
>>> However, in moving the js to the external file, when rendering the html
>>> page the variable values are no longer mapped to the variable name within
>>> the external js file. The information is still there, I was just wondering
>>> if I could somehow pull in the variable values without declaring global
>>> variables or hardcoding the urls in the js?
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To post to this group, send email to django...@googlegroups.com.
>>> To unsubscribe from this group, send email to django-users...@**
>>> googlegroups.com.
>>>
>>> Visit this group at 
>>> http://groups.google.com/**group/django-users?hl=en<http://groups.google.com/group/django-users?hl=en>
>>> .
>>> For more options, visit 
>>> https://groups.google.com/**groups/opt_out<https://groups.google.com/groups/opt_out>
>>> .
>>>
>>>
>>>
>>
>>
>>
>> --
>> Juan
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>



-- 
Juan

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to