pass variables from template to views in djangoDoes Django scale?Using % url ??? % in django templatesDjango Generic Template URL ReferenceDjango urls.py not rendering correct templateDjango reverse lookup rendering the same (wrong) templatewrong (same) django template returned for every urlMezzanine ignores the view, displays the template but does not pass the contextDjango Got an unexpected keyword argument 'id_speaker'How to pass a variable from one view to another in DjangoDjango - template not being detected

The cat ate your input again!

Is there a SQL/English like language that lets you define formulations given some data?

PhD advisor lost funding, need advice

A continuous water "planet" ring around a star

How do I call a 6-digit Australian phone number with a US-based mobile phone?

What kind of liquid can be seen 'leaking' from the upper surface of the wing of a Boeing 737-800?

How do some PhD students get 10+ papers? Is that what I need for landing good faculty position?

Can lodestones be used to magnetize crude iron weapons?

How can I find an old paper when the usual methods fail?

Boss wants me to ignore a software API license prohibiting mass download

What is a "soap"?

Running code generated in realtime in JavaScript with eval()

Telephone number in spoken words

Heating Margarine in Pan = loss of calories?

How was the murder committed?

Do I have to cite common CS algorithms?

Why is Python 2.7 still the default Python version in Ubuntu?

If I animate and control a zombie, does it benefit from Undead Fortitude when it's reduced to 0 HP?

Why am I not billed for EOB balance?

Why is the result of ('b'+'a'+ + 'a' + 'a').toLowerCase() 'banana'?

The cat exchanges places with a drawing of the cat

Swap on SSD in 2019?

How far did Gandalf and the Balrog drop from the bridge in Moria?

What can Amex do if I cancel their card after using the sign up bonus miles?



pass variables from template to views in django


Does Django scale?Using % url ??? % in django templatesDjango Generic Template URL ReferenceDjango urls.py not rendering correct templateDjango reverse lookup rendering the same (wrong) templatewrong (same) django template returned for every urlMezzanine ignores the view, displays the template but does not pass the contextDjango Got an unexpected keyword argument 'id_speaker'How to pass a variable from one view to another in DjangoDjango - template not being detected






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















On clicking on each location I have to fetch a text file from there. I need to pass these locations to the views.py to render the files.



template:



<script>
if(data.columns[j] == "outputFilePath")
var op = JSON.stringify(data.tableData[i][j]);
op = op.substring(1, op.length-1)
row.append("<td><a href='/dhl/outputDir'>" + op + "</a></td>")

</script>


views. py:



def outputDir(request,location):
text_data = open("location/stdout", "rb").read()
return HttpResponse(text_data, content_type="text/plain")


urls.py



url(r'^dhl/outputDir',views.outputDir),









share|improve this question


























  • Are you sure that's from your template file? Because that looks more like a mix of php and python, and not proper jinja2-syntax

    – Johan
    Mar 27 at 10:28












  • yes that is from a html file, code snippet here is the javascript part of the html

    – Shilpa Narayanan
    Mar 27 at 10:31











  • I see, I took the liberty to update the template code so it's a bit more obvious what happens :) However, can you emphasize what you need help with in your question? Currently your question states what you want to achieve, but it's not clear what you need help with. Take a minute to read How do I ask a good question? if you need help for how to formulate your question and code.

    – Johan
    Mar 27 at 10:51











  • How do I pass the variable 'op' to outputDir(views.py) so that I can fetch a file from the location---> text_data=open("op/stdout","rb").read() is possible

    – Shilpa Narayanan
    Mar 27 at 11:39

















0















On clicking on each location I have to fetch a text file from there. I need to pass these locations to the views.py to render the files.



template:



<script>
if(data.columns[j] == "outputFilePath")
var op = JSON.stringify(data.tableData[i][j]);
op = op.substring(1, op.length-1)
row.append("<td><a href='/dhl/outputDir'>" + op + "</a></td>")

</script>


views. py:



def outputDir(request,location):
text_data = open("location/stdout", "rb").read()
return HttpResponse(text_data, content_type="text/plain")


urls.py



url(r'^dhl/outputDir',views.outputDir),









share|improve this question


























  • Are you sure that's from your template file? Because that looks more like a mix of php and python, and not proper jinja2-syntax

    – Johan
    Mar 27 at 10:28












  • yes that is from a html file, code snippet here is the javascript part of the html

    – Shilpa Narayanan
    Mar 27 at 10:31











  • I see, I took the liberty to update the template code so it's a bit more obvious what happens :) However, can you emphasize what you need help with in your question? Currently your question states what you want to achieve, but it's not clear what you need help with. Take a minute to read How do I ask a good question? if you need help for how to formulate your question and code.

    – Johan
    Mar 27 at 10:51











  • How do I pass the variable 'op' to outputDir(views.py) so that I can fetch a file from the location---> text_data=open("op/stdout","rb").read() is possible

    – Shilpa Narayanan
    Mar 27 at 11:39













0












0








0








On clicking on each location I have to fetch a text file from there. I need to pass these locations to the views.py to render the files.



template:



<script>
if(data.columns[j] == "outputFilePath")
var op = JSON.stringify(data.tableData[i][j]);
op = op.substring(1, op.length-1)
row.append("<td><a href='/dhl/outputDir'>" + op + "</a></td>")

</script>


views. py:



def outputDir(request,location):
text_data = open("location/stdout", "rb").read()
return HttpResponse(text_data, content_type="text/plain")


urls.py



url(r'^dhl/outputDir',views.outputDir),









share|improve this question
















On clicking on each location I have to fetch a text file from there. I need to pass these locations to the views.py to render the files.



template:



<script>
if(data.columns[j] == "outputFilePath")
var op = JSON.stringify(data.tableData[i][j]);
op = op.substring(1, op.length-1)
row.append("<td><a href='/dhl/outputDir'>" + op + "</a></td>")

</script>


views. py:



def outputDir(request,location):
text_data = open("location/stdout", "rb").read()
return HttpResponse(text_data, content_type="text/plain")


urls.py



url(r'^dhl/outputDir',views.outputDir),






django django-views django-urls






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 27 at 10:48









Johan

2,6281 gold badge7 silver badges19 bronze badges




2,6281 gold badge7 silver badges19 bronze badges










asked Mar 27 at 10:16









Shilpa NarayananShilpa Narayanan

31 bronze badge




31 bronze badge















  • Are you sure that's from your template file? Because that looks more like a mix of php and python, and not proper jinja2-syntax

    – Johan
    Mar 27 at 10:28












  • yes that is from a html file, code snippet here is the javascript part of the html

    – Shilpa Narayanan
    Mar 27 at 10:31











  • I see, I took the liberty to update the template code so it's a bit more obvious what happens :) However, can you emphasize what you need help with in your question? Currently your question states what you want to achieve, but it's not clear what you need help with. Take a minute to read How do I ask a good question? if you need help for how to formulate your question and code.

    – Johan
    Mar 27 at 10:51











  • How do I pass the variable 'op' to outputDir(views.py) so that I can fetch a file from the location---> text_data=open("op/stdout","rb").read() is possible

    – Shilpa Narayanan
    Mar 27 at 11:39

















  • Are you sure that's from your template file? Because that looks more like a mix of php and python, and not proper jinja2-syntax

    – Johan
    Mar 27 at 10:28












  • yes that is from a html file, code snippet here is the javascript part of the html

    – Shilpa Narayanan
    Mar 27 at 10:31











  • I see, I took the liberty to update the template code so it's a bit more obvious what happens :) However, can you emphasize what you need help with in your question? Currently your question states what you want to achieve, but it's not clear what you need help with. Take a minute to read How do I ask a good question? if you need help for how to formulate your question and code.

    – Johan
    Mar 27 at 10:51











  • How do I pass the variable 'op' to outputDir(views.py) so that I can fetch a file from the location---> text_data=open("op/stdout","rb").read() is possible

    – Shilpa Narayanan
    Mar 27 at 11:39
















Are you sure that's from your template file? Because that looks more like a mix of php and python, and not proper jinja2-syntax

– Johan
Mar 27 at 10:28






Are you sure that's from your template file? Because that looks more like a mix of php and python, and not proper jinja2-syntax

– Johan
Mar 27 at 10:28














yes that is from a html file, code snippet here is the javascript part of the html

– Shilpa Narayanan
Mar 27 at 10:31





yes that is from a html file, code snippet here is the javascript part of the html

– Shilpa Narayanan
Mar 27 at 10:31













I see, I took the liberty to update the template code so it's a bit more obvious what happens :) However, can you emphasize what you need help with in your question? Currently your question states what you want to achieve, but it's not clear what you need help with. Take a minute to read How do I ask a good question? if you need help for how to formulate your question and code.

– Johan
Mar 27 at 10:51





I see, I took the liberty to update the template code so it's a bit more obvious what happens :) However, can you emphasize what you need help with in your question? Currently your question states what you want to achieve, but it's not clear what you need help with. Take a minute to read How do I ask a good question? if you need help for how to formulate your question and code.

– Johan
Mar 27 at 10:51













How do I pass the variable 'op' to outputDir(views.py) so that I can fetch a file from the location---> text_data=open("op/stdout","rb").read() is possible

– Shilpa Narayanan
Mar 27 at 11:39





How do I pass the variable 'op' to outputDir(views.py) so that I can fetch a file from the location---> text_data=open("op/stdout","rb").read() is possible

– Shilpa Narayanan
Mar 27 at 11:39












1 Answer
1






active

oldest

votes


















0














You can use basic template tags and default view functionality by passing parameters.



However, what you're trying to achieve, will make the view wide open for anyone to access folders in your application by entering any folder they want. You could add a list of allowed locations, which I have done in my solution below.



Template



if(data.columns[j] == "outputFilePath")
var op = JSON.stringify(data.tableData[i][j]);
op = op.substring(1, op.length-1)
row.append("<td><a href='/dhl/outputDir/" + op + "'>" + op + "</a></td>")



views.py



def outputDir(request, location):
# Make sure to check if the location is in the list of allowed locations
if location in allowed_locations:
text_data = open(location + "/stdout", "rb").read()
return HttpResponse(text_data, content_type="text/plain")
else:
return PermissionDenied


You also need to add a parameter to the url:



urls.py



url(r'^dhl/outputDir/(?P<location>w+)', views.outputDir),





share|improve this answer

























  • Thanks Johan, the above method worked perfectly

    – Shilpa Narayanan
    Apr 1 at 9:31











  • @ShilpaNarayanan No problem! If you feel it was an adequate answer that helped you, consider marking it as an accepted solution. Or if you want to be open for more possible answers you can just leave it as it is :)

    – Johan
    Apr 1 at 10:16










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55374750%2fpass-variables-from-template-to-views-in-django%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














You can use basic template tags and default view functionality by passing parameters.



However, what you're trying to achieve, will make the view wide open for anyone to access folders in your application by entering any folder they want. You could add a list of allowed locations, which I have done in my solution below.



Template



if(data.columns[j] == "outputFilePath")
var op = JSON.stringify(data.tableData[i][j]);
op = op.substring(1, op.length-1)
row.append("<td><a href='/dhl/outputDir/" + op + "'>" + op + "</a></td>")



views.py



def outputDir(request, location):
# Make sure to check if the location is in the list of allowed locations
if location in allowed_locations:
text_data = open(location + "/stdout", "rb").read()
return HttpResponse(text_data, content_type="text/plain")
else:
return PermissionDenied


You also need to add a parameter to the url:



urls.py



url(r'^dhl/outputDir/(?P<location>w+)', views.outputDir),





share|improve this answer

























  • Thanks Johan, the above method worked perfectly

    – Shilpa Narayanan
    Apr 1 at 9:31











  • @ShilpaNarayanan No problem! If you feel it was an adequate answer that helped you, consider marking it as an accepted solution. Or if you want to be open for more possible answers you can just leave it as it is :)

    – Johan
    Apr 1 at 10:16















0














You can use basic template tags and default view functionality by passing parameters.



However, what you're trying to achieve, will make the view wide open for anyone to access folders in your application by entering any folder they want. You could add a list of allowed locations, which I have done in my solution below.



Template



if(data.columns[j] == "outputFilePath")
var op = JSON.stringify(data.tableData[i][j]);
op = op.substring(1, op.length-1)
row.append("<td><a href='/dhl/outputDir/" + op + "'>" + op + "</a></td>")



views.py



def outputDir(request, location):
# Make sure to check if the location is in the list of allowed locations
if location in allowed_locations:
text_data = open(location + "/stdout", "rb").read()
return HttpResponse(text_data, content_type="text/plain")
else:
return PermissionDenied


You also need to add a parameter to the url:



urls.py



url(r'^dhl/outputDir/(?P<location>w+)', views.outputDir),





share|improve this answer

























  • Thanks Johan, the above method worked perfectly

    – Shilpa Narayanan
    Apr 1 at 9:31











  • @ShilpaNarayanan No problem! If you feel it was an adequate answer that helped you, consider marking it as an accepted solution. Or if you want to be open for more possible answers you can just leave it as it is :)

    – Johan
    Apr 1 at 10:16













0












0








0







You can use basic template tags and default view functionality by passing parameters.



However, what you're trying to achieve, will make the view wide open for anyone to access folders in your application by entering any folder they want. You could add a list of allowed locations, which I have done in my solution below.



Template



if(data.columns[j] == "outputFilePath")
var op = JSON.stringify(data.tableData[i][j]);
op = op.substring(1, op.length-1)
row.append("<td><a href='/dhl/outputDir/" + op + "'>" + op + "</a></td>")



views.py



def outputDir(request, location):
# Make sure to check if the location is in the list of allowed locations
if location in allowed_locations:
text_data = open(location + "/stdout", "rb").read()
return HttpResponse(text_data, content_type="text/plain")
else:
return PermissionDenied


You also need to add a parameter to the url:



urls.py



url(r'^dhl/outputDir/(?P<location>w+)', views.outputDir),





share|improve this answer













You can use basic template tags and default view functionality by passing parameters.



However, what you're trying to achieve, will make the view wide open for anyone to access folders in your application by entering any folder they want. You could add a list of allowed locations, which I have done in my solution below.



Template



if(data.columns[j] == "outputFilePath")
var op = JSON.stringify(data.tableData[i][j]);
op = op.substring(1, op.length-1)
row.append("<td><a href='/dhl/outputDir/" + op + "'>" + op + "</a></td>")



views.py



def outputDir(request, location):
# Make sure to check if the location is in the list of allowed locations
if location in allowed_locations:
text_data = open(location + "/stdout", "rb").read()
return HttpResponse(text_data, content_type="text/plain")
else:
return PermissionDenied


You also need to add a parameter to the url:



urls.py



url(r'^dhl/outputDir/(?P<location>w+)', views.outputDir),






share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 27 at 12:05









JohanJohan

2,6281 gold badge7 silver badges19 bronze badges




2,6281 gold badge7 silver badges19 bronze badges















  • Thanks Johan, the above method worked perfectly

    – Shilpa Narayanan
    Apr 1 at 9:31











  • @ShilpaNarayanan No problem! If you feel it was an adequate answer that helped you, consider marking it as an accepted solution. Or if you want to be open for more possible answers you can just leave it as it is :)

    – Johan
    Apr 1 at 10:16

















  • Thanks Johan, the above method worked perfectly

    – Shilpa Narayanan
    Apr 1 at 9:31











  • @ShilpaNarayanan No problem! If you feel it was an adequate answer that helped you, consider marking it as an accepted solution. Or if you want to be open for more possible answers you can just leave it as it is :)

    – Johan
    Apr 1 at 10:16
















Thanks Johan, the above method worked perfectly

– Shilpa Narayanan
Apr 1 at 9:31





Thanks Johan, the above method worked perfectly

– Shilpa Narayanan
Apr 1 at 9:31













@ShilpaNarayanan No problem! If you feel it was an adequate answer that helped you, consider marking it as an accepted solution. Or if you want to be open for more possible answers you can just leave it as it is :)

– Johan
Apr 1 at 10:16





@ShilpaNarayanan No problem! If you feel it was an adequate answer that helped you, consider marking it as an accepted solution. Or if you want to be open for more possible answers you can just leave it as it is :)

– Johan
Apr 1 at 10:16








Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55374750%2fpass-variables-from-template-to-views-in-django%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현