i need help with my django project. I am trying to open folder from django view and I came up with idea which will execute python script which will handle this part, because for some security reasons Chrome is not able to directly open file explorer (program).
So I tried this.
detail.html looks:
<form class="form" method='post'>
{% csrf_token %}
<button style="width:100%;" type='explorer' name='explorer' value='explorer' class="btn btn-info btn-min-width"><i class="fa fa-folder"></i> Navigate to folder</button>
</form>
actions.py looks:
def openexplorer():
return os.system('explorer')
view.py looks:
def detail(request, Pools_id):
try:
je = More.objects.get(pk=Pools_id)
except More.DoesNotExist:
raise Http404("Question does not exist")
return render(request, 'rc/detail.html', {'more_identification': je})
if request.method == 'POST':
if 'explorer' in request.POST:
openexplorer()
I am rendring the page and i only want to execute the script when the button is clicked. Can someone please help? I think there is some error in view.py.
Thanks a lot !
Okay, I found it. just put the if statement under try and it works fine:) That's cool
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.