Django 1.7冲突模型 [英] Django 1.7 conflicting models
本文介绍了Django 1.7冲突模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
异常类型:RuntimeError at /
异常值:冲突人模型应用程式'resume':< class
'apps.resume.models.Person'>和< class'resume.models.Person'>。
Django使用两个不同的模板导入相同的模型。如何修复?
全错误日志:
追溯:
文件/home/voxa/.virtualenvs/42-test/local/lib/python2.7/site-packages/django/core/handlers/base.pyin get_response
98. resolver_match = resolver.resolve(request.path_info)
解析$文件/home/voxa/.virtualenvs/42-test/local/lib/python2.7/site-packages/django/core/urlresolvers.py b $ b 343.对于self.url_patterns中的模式:
文件/home/voxa/.virtualenvs/42-test/local/lib/python2.7/site-packages/django/core/urlresolvers.py在url_patterns
372. patterns = getattr(self.urlconf_module,urlpatterns,self.urlconf_module)
文件/home/voxa/.virtualenvs/42-test/local/lib/python2.7/ urlconf_module中的site-packages / django / core / urlresolvers.py
366. self._urlconf_module = import_module(self.urlconf_name)
文件/usr/lib/python2.7/importlib/__init__.py in import_module
37. __import __(name)
Fil < module>中的/home/voxa/django/FortyTwoTestTask/fortytwo_test_task/urls.py
4.从简历导入视图
< module>中的文件/home/voxa/django/FortyTwoTestTask/apps/resume/views.py
4.从resume.models import Person
文件/home/voxa/django/FortyTwoTestTask/apps/resume/models.py在< module>
3. class Person(models.Model):
文件/home/voxa/.virtualenvs/42-test/local/lib/python2.7/site-packages/django/db/models/ base.py在__new__
285. new_class._meta.apps.register_model(new_class._meta.app_label,new_class)
文件/home/voxa/.virtualenvs/42-test/local/lib/ python2.7 / site-packages / django / apps / registry.pyin register_model
213.(model_name,app_label,app_models [model_name],model))
异常类型:RuntimeError at /
异常值:在应用程序resume中冲突person模型:< class'apps.resume.models.Person'>和< class'resume.models.Person'>。
解决方案
而不是导入所有项目,然后应用程序然后应用程序内的模块只需导入项目中的应用程序,然后是模块。
而不是
从webproject.app导入模型
使用
从应用导入模型
或
from app.models import Staffs
I install my application in "project/apps/myapp" folder. Both apps and myapp folders have init.py files(Without any of them there is module missing error). Now I've the error:
Exception Type: RuntimeError at /
Exception Value: Conflicting 'person' models in application 'resume': <class
'apps.resume.models.Person'> and <class 'resume.models.Person'>.
Django import the same model with two different pathes. How can I fix it?
Full error log:
Traceback:
File "/home/voxa/.virtualenvs/42-test/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
98. resolver_match = resolver.resolve(request.path_info)
File "/home/voxa/.virtualenvs/42-test/local/lib/python2.7/site-packages/django/core/urlresolvers.py" in resolve
343. for pattern in self.url_patterns:
File "/home/voxa/.virtualenvs/42-test/local/lib/python2.7/site-packages/django/core/urlresolvers.py" in url_patterns
372. patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/home/voxa/.virtualenvs/42-test/local/lib/python2.7/site-packages/django/core/urlresolvers.py" in urlconf_module
366. self._urlconf_module = import_module(self.urlconf_name)
File "/usr/lib/python2.7/importlib/__init__.py" in import_module
37. __import__(name)
File "/home/voxa/django/FortyTwoTestTask/fortytwo_test_task/urls.py" in <module>
4. from resume import views
File "/home/voxa/django/FortyTwoTestTask/apps/resume/views.py" in <module>
4. from resume.models import Person
File "/home/voxa/django/FortyTwoTestTask/apps/resume/models.py" in <module>
3. class Person(models.Model):
File "/home/voxa/.virtualenvs/42-test/local/lib/python2.7/site-packages/django/db/models/base.py" in __new__
285. new_class._meta.apps.register_model(new_class._meta.app_label, new_class)
File "/home/voxa/.virtualenvs/42-test/local/lib/python2.7/site-packages/django/apps/registry.py" in register_model
213. (model_name, app_label, app_models[model_name], model))
Exception Type: RuntimeError at /
Exception Value: Conflicting 'person' models in application 'resume': <class 'apps.resume.models.Person'> and <class 'resume.models.Person'>.
解决方案
Instead of importing the all project then the app then the module inside the app just import the app which is inside the project then the module.
Instead of
from webproject.app import model
Use
from app import model
or
from app.models import Staffs
这篇关于Django 1.7冲突模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文