My views.py file code:
#!/usr/bin/python
from django.template import loader, RequestContext
from django.http import HttpResponse
#from skey import find_root_tags, count, sorting_list
from search.models import Keywords
from django.shortcuts import render_to_response as rr
def front_page(request):
if request.method == 'POST' :
from skey import find_root_tags, count, sorting_list
str1 = request.POST['word']
fo = open("/home/pooja/Desktop/xml.txt","r")
for i in range(count.__len__()):
file = fo.readline()
file = file.rstrip('\n')
find_root_tags(file,str1,i)
list.append((file,count[i]))
sorting_list(list)
for name, count1 in list:
s = Keywords(file_name=name,frequency_count=count1)
s.save()
fo.close()
list1 = Keywords.objects.all()
t = loader.get_template('search/results.html')
c = RequestContext({'list1':list1,
})
return HttpResponse(t.render(c))
else :
str1 = ''
list = []
template = loader.get_template('search/front_page.html')
c = RequestContext(request)
response = template.render(c)
return HttpResponse(response)
the variable “file” that I’m sending in function find_root_tags(file,str1,i) has a xml file’s name. This file is present on my desktop, and this code is written in views.py file of my django app, so it is unable to open that file. How can I open that file because xml.txt contains similar filenames that are to be read and then opened. In short, how can I send the file argument as:
file1 = '/home/pooja/Desktop/<filename>'
here <filename> equals the value stored in variable file and finall able to call it as:
find_root_tags(file1, str1, i)
////////////////////////////////////////////////////////////////////////////////////////////
clarification :
1) please refer to the variable “file” in which you can see that I’m storing the read content of xml.txt.
2)xml.txt contains xml filenames. The views.py file is the part of django app’s which is unable to open these files since they are present on desktop.
3) my question is how to modify and send the file variable containing filename appended with it’s absolute path which is:
'/home/pooja/Desktop/filename'
by doing this it will open the files present on the Desktop.
try this: