ajax loading html

63 views
Skip to first unread message

ledzgio

unread,
Jul 12, 2012, 5:19:07 PM7/12/12
to django...@googlegroups.com
Hi,

I have to load with ajax (using qtip2) a certain HTML file, and I have to specify a URL to the html page, that is located within the template directory. I have tried but the path doesn't mach. Should I have to add a line to the urls.py and views.py? or can I load that HTML page in other way? if yes, how can I load that page?

thanks

Daniel Svonava

unread,
Jul 13, 2012, 10:40:48 AM7/13/12
to django...@googlegroups.com
Hi,

If this is just a one-off thing, the simplest way might be just symlinking that html file to a folder where you serve your static assets from (e.g. page_media).

Cheers,
Daniel

ledzgio

unread,
Jul 14, 2012, 12:24:19 PM7/14/12
to django...@googlegroups.com
It is for showing an HTML page with qtips2 as ajax tip. Are there any other solutions for this?

Tomas Neme

unread,
Jul 14, 2012, 12:34:15 PM7/14/12
to django...@googlegroups.com
an "html page" can't be located within the templates directory, an
HTML file might, but what is it you want to do, exactly? you want to
render a static file? does it make sense going through django for
this?

URLs point to views, not templates, the views are which decide what
templates to use (the same view could use different templates in case
there's errors, or depending on whether the user is logged in or not,
for example).

In any case, you should set up an URL to make your ajax call to, if
you want to go through django for this, something like

url(r'path/to/tip/$',
TemplateView.as_view(template="path/to/template.html"),
name="ajax_tooltip")

docs on the matter of TemplateViews:
https://docs.djangoproject.com/en/dev/ref/class-based-views/base/#django.views.generic.base.TemplateView

If you don't want to write an url for this, then you don't want to
handle it through django. If that's the case, as someone explained,
you can just put the html file somewhere OFF your templates directory,
and have your webserver (apache, or nginx, or whatever you're using)
serve that url by itself (you'll still have to set up the URL in the
webserver's config files)

--
"The whole of Japan is pure invention. There is no such country, there
are no such people" --Oscar Wilde

|_|0|_|
|_|_|0|
|0|0|0|

(\__/)
(='.'=)This is Bunny. Copy and paste bunny
(")_(") to help him gain world domination.

ledzgio

unread,
Jul 14, 2012, 12:49:57 PM7/14/12
to django...@googlegroups.com
Thanks for your response.

What I want to do is to make use of this qtip2 feauture

http://craigsworks.com/projects/qtip2/demos/#ajax

where I pass a certain HTML file to render into the tip. I would prefere to manage it through django because I can have models data into the HTML file to render certain data.

I am going to try the TemplateView method.
Message has been deleted

Tomas Neme

unread,
Jul 14, 2012, 3:33:24 PM7/14/12
to django...@googlegroups.com
On Sat, Jul 14, 2012 at 2:11 PM, ledzgio <giorgio...@gmail.com> wrote:
> If I use the TemplateViews method, should I have to set anything on the
> views.py? and how can I point that file from template?

the TemplateView is a view, it's already been written for you, so you
can use it without adding anything new. If you want to add some custom
behavior to it, you can subclass it, or skip it completely and make a
new view, either out of mixin classes, or function-based (though that
method's being deprecated in the future). That you'd usually do in
your views.py file (bearing in mind that it's not mandatory that it's
called that, it's just a convention), but for this case (at least as
far as you've described it) I don't think you need any specific
behavior.

And how can you point what file from which template?

That being said: My real recommendation would be go do the tutorial
and understand the concepts. Then go read about Class-based views, and
understand all that on a conceptual level, as well.

I.. don't mean to sound harsh, but all your questions and the place
they seem to point to give out a feeling that you're not really
understanding django and it's underlying concepts, it'll be very hard
for you to ask the right questions unless you figure it out first, and
even harder for us to answer them.

A template is just some text that can be mixed with some programming
structures (loops, ifs, and other template tags and filters) and
variables. The HTML you actually send the client could be (and usually
is) built from a mixture of a number of different templates, so you
should get yourself rid of that concept of "HTML page" = "template
file" you seem to be carrying.

At this point, I think the best thing you could do is be a little more
explicit, tell us what you're trying to do, possibly paste some models
and urls files
Reply all
Reply to author
Forward
0 new messages