将主Django项目views.py中的视图导入到应用程序的views.py中时遇到问题。
会发生这种情况:
ImportError:无法从“ ebdjango.views”导入名称“ index” (/Users/iamsuccessful/ebdjango/ebdjango/views.py)
dailytask / views.py(应用文件夹)内部
ticks_x=[0.2,Vc,0.4,0.6,0.8,1,1.2]
ticks_y=[-50,0,Pc,50,100,150,200]
xticks(ticks_x)
yticks(ticks_y)
for x1 in ticks_x:
if x1!= Vc:
axvline(x=x1, color = 'k', linestyle = '-', linewidth = 0.2)
for y1 in ticks_y:
if y1!= Pc:
axhline(y=y1, color = 'k', linestyle = '-', linewidth = 0.2)
在ebdjango / views.py内部(Django项目主文件夹)
from ebdjango.views import index
settings.py
@login_required(login_url="/login")
def index(request):
user = request.user
if user.userprofile.daily_task_done is False:
return render(request, 'home.html')
elif user.userprofile.daily_task_done is True:
return task_done(request, pk=user.userprofile.daily_task)
我需要怎么做才能将视图索引导入到应用程序views.py中?
答案 0 :(得分:0)
ebdjango/
和dailytask/
文件夹中都包含__init__.py
个文件吗?