Accessing view from javascript

50 views
Skip to first unread message

Gary Roach

unread,
Dec 17, 2015, 7:54:35 PM12/17/15
to django...@googlegroups.com
Hi all

I am new to this and am really struggling with what should be a simple
problem. I have a main.html that has javascript code. There is a switch
statement. From the first case statement, I wish to load a template that
is the child of main.html. I have a /home/view.py with:

def welcome(request):
return render(request, "home/welcome.html") in it.

I also have /template/home/welcome.html which is ultimately what I wish
to have returned.

I have jQuery loaded in main.html but have no idea how to use it.

What can I put in the javascript case statement to return welcome.html.

Welcome.html is:

<!--Web page for Welcome text-->
{% extends "home/main.html" %}
<!--{% load staticfiles %}-->

{% block content %}
<p>"yOU ARE IN WELCOME HTML"</p>
<<<!--{% include "home/readMeFirst.html" %}-->
{% endblock %}

There is a block content statement in the body of main.html


Gary R.

Galia Ladiray

unread,
Dec 18, 2015, 12:45:22 AM12/18/15
to Django users, gary71...@verizon.net
I don't exactly understand what you are trying to do (what are you switching on? must you do this in JavaScript?)

But in order to load server content you can use either JQuery Get method

Where you will create an empty div in your HTML, and put the server response in this div (with JQuery html method)

Or simply have two django views on different URLs, and then in your JS you will load the required page

But again I'm not sure what is your use case, why do you need to have your switch case in JS and not in the view ....
Reply all
Reply to author
Forward
0 new messages