简体   繁体   English

Django视图不存在或无法导入

[英]Django views does not exist or could not import

This morning i have been working on my project. 今天早上我一直在研究我的项目。 I finished what i was doing and i pushed new code to git. 我完成了我正在做的事情,我将新代码推送到git。

Now, i went to run my project to start working on it and index view does not run! 现在,我去运行我的项目开始工作,索引视图不运行!

Could not import ism.views.index. View does not exist in module ism.views.

This view ran without any kind of problem. 这个视图没有任何问题。 All the project ran. 所有的项目都运行了。

There is something more incredible. 有更令人难以置信的事情。 i tried and checked other views after main view (ism.views.index) failed and all of them worked, but not now! 我在主视图(ism.views.index)失败后尝试并检查了其他视图,但所有这些视图都有效,但现在不行! All the views ran correctly 10 seconds ago and now neither works. 10秒前所有视图都正确运行,现在都无法正常工作。 They spit the same error of main view. 他们吐出与主视图相同的错误。

I found searching around the Internet this related topic: 我发现在互联网上搜索这个相关主题:

It's magic the view does not exist for django but it worked 5 secondes before and it still exist 对于django而言,这种观点并不存在,但是它之前有5个secondes并且它仍然存在

But i have tried to remove original file (views.py in ism app) and to write it again, and the problem persist. 但我试图删除原始文件(ism应用程序中的views.py)并再次写入,问题仍然存在。 The same with all the rest views.py. 所有其余的views.py都一样。

Anyone knows something about this issue? 有人知道这个问题吗?

Thanks =) 谢谢=)

Try doing a 尝试做一个

    python ./manage.py shell

and then importing the view that is giving you the problem. 然后导入提供问题的视图。 That might end up giving you more useful debugging information. 这最终可能会为您提供更有用的调试信息。

> from ism.views import index

it happend to me, evevtually the problem was i had a syntax error in one of the forms in forms.py, and i imported this form into my views.py file. 它发生在我身上,事实上问题是我在forms.py中的一个表单中出现语法错误,并且我将此表单导入到我的views.py文件中。 Django error message still pointed me to view does not exist error Django错误信息仍指向我查看不存在错误

I had the same error for the same reason. 出于同样的原因我也有同样的错误。 Typo in another file that was imported by the one reported in the error. 在错误中报告的文件中导入的另一个文件中的错字。 Revealed by importing manually into the shell. 通过手动导入shell来显示。

Thanks kdazzle! 谢谢kdazzle!

--Fred Stluka - 弗雷德斯图卡

我设法通过在vim中打开视图文件并保存而没有任何更改来解决问题。

Same problem. 同样的问题。

My shell was not working too. 我的外壳也没用。

I saw the link that Jimenez posted, and at the end of discussion the guy solved the problem saving the file using Vim. 我看到了Jimenez发布的链接,在讨论结束时,这个人解决了使用Vim保存文件的问题。

I rewrited the file using Vim and it worked! 我使用Vim重写了文件,它工作了!

Try it if your was not solved yet! 如果您还没有解决,请尝试一下!

I had the same problem. 我有同样的问题。

I had no clues, importing the module in the shell was not helpful at all: AttributeError: 'module' object has no attribute 'views' . 我没有线索,在shell中导入模块根本没有帮助: AttributeError: 'module' object has no attribute 'views'
But I noticed that if I imported a specific module (that is imported in the views.py) before importing views, it worked. 但是我注意到如果我在导入视图之前导入了一个特定的模块(在views.py中导入),它就可以了。

I finally figured that the imported module also imported views.py , so it failed as each file was importing the other. 我终于认为导入的模块还导入了views.py ,因此每个文件导入另一个文件时失败。 No explicit message anywhere though. 尽管如此,没有明确的信息

Same issue because of cross view import between two files. 同一问题是因为两个文件之间的跨视图导入。

I've resolve it by moving import inside of each method. 我通过在每个方法中移动导入来解决它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM