last day (23 days later) » 

10:54 AM
Hi, as i was just explaining i am getting this key error. not sure why. could you help me?
 
Hi, I can try...can you paste the error here again ?
 
Thanks, The error was --KeyError at /uploaddata/

'user'
shows the error in line after else:
here -- user = form.cleaned_data['user']
datafile = form.cleaned_data['datafile']
 
your form response...doesn't have a user in the json reponse...check the field...
 
oh, i'm pretty new to django. i dont understand where to check json?
 
give me the template file ?
 
11:06 AM
i have a form to be filled and after the form is submitted, a new page for uploading the file is opened. that is the uploaddata template. It has the same ID from the previous form
you mean you want to see the uploaddata template? please dont get mad for my silly questions
 
np thats fine.....you will be rendering a template to browser...there will be fields mapped to that...that field will be used by the views.py for processing..
 
formy.py
class uploadmetaform(forms.ModelForm):
count = Metadataform.objects.all().latest('id').id #To know the id of latest object
data = Metadataform.objects.all().filter(id=count) #return the queryset with only latest object
path = forms.ModelChoiceField(queryset=data, initial=0, label='Meta ID')

def __init__(self, *args, **kwargs):
super(uploadmetaform, self).__init__(*args, **kwargs)
count = Metadataform.objects.all().latest('id').id
data = Metadataform.objects.all().filter(id=count)
self.fields['path'] = forms.ModelChoiceField(queryset=data, initial=0, label='Meta ID')
uploaddata.html
<h2>Dataset Upload</h2>

<form method="post" enctype="multipart/form-data">



{% csrf_token %}
{{ form.as_p }}


<button type="submit" class="btn btn-primary">Upload File</button>


</form>
 
replace user with datafile
 
ok. trying
 
sorry..path
user with path
 
11:13 AM
but i have all three here:
else:
user = form.cleaned_data['user']
datafile = form.cleaned_data['datafile']
path = dict(form.fields['path'].path)[path]
270. path = form.cleaned_data['path']

Exception Type: KeyError at /uploaddata/
Exception Value: 'user'
'ModelChoiceField' object has no attribute 'path' should i just comment the dict part. because its not choice field for me
 
I am confused....I need to say your entire code..
 
i dont have an excusive git hub. Should i send you the code in parts models.py, forms and views?
now i get this error: local variable 'user' referenced before assignment
                                    b = form(path=path, user=user, datafile=datafile)
 
11:37 AM
def uploaddata(request):
if request.user.is_authenticated:

if request.method == 'POST':
form = uploadmetaform(request.POST, request.FILES)

if form.is_valid():
path = form.cleaned_data['path']
if uploadmeta.objects.filter(path=path).exists():
user = form.cleaned_data['user']
datafile = form.cleaned_data['datafile']
context = {
'path': path,
'user': user,
'datafile': datafile
}

template = loader.get_template('nameexists.html')
return HttpResponse(template.render(context, request))
else:
user = form.cleaned_data['user']
can i interchange the IF and the else condition?
 
12:13 PM
I need the template file that will be rendered when the user hits the api..not when the response is taken...a template will be rendered that asks for input...
 

  last day (23 days later) »