Thursday, September 27, 2012

Re: Regarding Template rendering

On Thu, Sep 27, 2012 at 9:53 AM, raju akula <akula.raju1@gmail.com> wrote:
>
>
> I am new to django, iam facing some issue with template ,
>
>
> i am having tabs,on click of each tab i need to load the template with the
> help of ajax. this is working fine if i use this script code in same html
> file,
> As per my requirement i have to use the external javascript file to maintain
> all the scripts . so i moved this whole script to external js file then
> template was not loading I dont have any clue on this. can any one guys help
> me out in this.
>
>
> <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.

No comments:

Post a Comment