ViewDoesNotExist Error

By : rv_k
Source: Stackoverflow.com
Question!

i am trying to do a simple Django application where employee list is read from database and displayed. for that i defined the models and entered the values to database through Django admin. But while trying to display data from database i am stuck with an error, "ViewDoesNotExist at /employeeProfile/ : Could not import task.employeeDetails.views. Error was: cannot import name emp_profile ".I am relatively new to django,so please help me to solve this. i will paste the code here.enter code here VIEWS.PY

from django.shortcuts import render_to_response
from django.contrib.auth.models import*
from task.employeeDetails.models import *
from django.conf import settings
from django.http import HttpResponse
from task.employeeDetails import emp_profile

def employeeList(request):
    tableList = EmployeeDetails.objects.all()
    return render_to_response('employeeList.html', {'emp_list': tableList})

def employeeProfile(request):
    profile = EmployeeDetails.objects.all()
    return render_to_response('employeeProfile.html',{'emp_profile':emp_profile})

URLS.PY

(r'^employeeProfile/$','task.employeeDetails.views.employeeProfile'),

TEMPLATE

<html>
<body>

{%for emp in emp_profile%}
<tr> <td>{{ emp.userName }} {{ emp.designation }} {{  emp.employeeID }}</td> </tr><td>
{%endfor%}
</table></h4>
</body>
</html>
By : rv_k


Answers

I assume you want:

def employeeProfile(request): profile = EmployeeDetails.objects.all() 
return render_to_response('employeeProfile.html',{'emp_profile':profile})

As Yuji pointed out, it looks like emp_profile isn't defined anywhere

By : danny


def employeeProfile(request):
    profile = EmployeeDetails.objects.all()
    return render_to_response('employeeProfile.html',{'emp_profile':emp_profile})

You named it profile on line 2, and then you tried to put it in the dictionary as emp_profile on line 3.



This video can help you solving your question :)
By: admin