开发者

ViewDoesNotExist Error

开发者 https://www.devze.com 2023-02-13 08:00 出处:网络
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

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 past开发者_JAVA技巧e 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>


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.


from task.employeeDetails import emp_profile

What is emp_profile and where exactly is it? from the looks of it, employeeDetails is the name of your directory, so unless emp_profile is a file in employeeDetails/, is defined in employeeDetails/__init__.py (or otherwise imported there), it will throw an import error.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消