Thursday, September 27, 2012

Re: Regarding Template rendering

Django will not parse the template tags inside your external JS file. What I would do is declare a JS variable in your template:
var URL_ABCPAGE = "{% url abcpage_ajax %}"
...

Then in you external JS file, you reference those variables:
$("#content").load(URL_ABCPAGE);

On Thu, Sep 27, 2012 at 11:05 PM, Joel Goldstick <joel.goldstick@gmail.com> wrote:
On Thu, Sep 27, 2012 at 9:53 AM, raju akula <akula.raju1@gmail.com> wrote:
> <html>
> <header></header>
> <section>
>
> <section>
>
> <script type="text/javascript">
>
>     $(function () {
>         $("#abc").click(function () {
>         $("#content").load('{% url abcpage_ajax %}');
>
>         $(this).addClass('active');
>         $("#def").removeClass('active').addClass('inactive');
>         $("#fgh").removeClass('active').addClass('inactive');
>         return false;
>         });
>
>         $("#def").click(function () {
>         $("#content").load('{% url cdepage_ajax %}');
>
>         $("#abc").removeClass('active').addClass('inactive');
>         $(this).addClass('active');
>         $("#fgh").removeClass('active').addClass('inactive');
>         return false;
>         });
>
>         $("#fgh").click(function () {
>         $("#content").load('{% url create_reports_ajax %}');
>
>         $("#abc").removeClass('active').addClass('inactive');
>         $("#def").removeClass('active').addClass('inactive');
>         $(this).addClass('active');
>         return false;
>         });
>
>
>     });
>
> </script>
>
>
>         <div id="content" class="content"> <!-- content -->
>
>             <div class="ipad-text">
>
>                 <h4>&nbsp;</h4>
>
>               <p> data</p>
>                 <a class="button long morebtn" href="{% url abcpage %}">
> button</a>
>
>             </div>
>
>
>
>         </div>    <!-- END content -->
>
>     </section>
>
>
> </html>
>
You need to put your javascript file in a directory where you put your
static files.  From my settings file:
(this is django 1.4)

STATIC_ROOT = os.path.join(SITE_ROOT, 'static')

# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
STATIC_URL = '/static/'

# Additional locations of static files
STATICFILES_DIRS = (
    # Put strings here, like "/home/html/static" or "C:/www/django/static".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
    os.path.join(STATIC_ROOT, 'css'),
    os.path.join(STATIC_ROOT, 'js'),
)

In your template you need to specify the static url
--
Joel Goldstick

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.


--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment