Django-inline-media get_model error - django

I am using Django 1.9 and for my project I need django-inline-media. I have done all stuff properly as per documentation. But I get this error.
File "/home/sifat/PycharmProjects/fear/profiles/models.py", line 3, in <module>
from inline_media.fields import TextFieldWithInlines
File "/home/sifat/PycharmProjects/fear/env/local/lib/python2.7/site- packages/inline_media/fields.py", line 4, in <module>
from django.db.models import fields, get_model
ImportError: cannot import name get_model
Now what to do? As it is error from a library

django.db.models.get_model has been deprecated in Django 1.7 and was removed in 1.9.
In Django 1.9, you can replace it with
from django.apps import apps
model = apps.get_model('app_name', 'model_name')

Related

flask_bcrypt, werkzeug.security.safe_str_cmp fails after upgrade to latest flask 2.1

I've upgraded my project to latest flask (2.1.2 and now I'm getting following error:
Traceback (most recent call last):
File "/home/ff/conveyors/run.py", line 1, in <module>
from conveyors import create_app
File "/home/ff/conveyors/conveyors/__init__.py", line 4, in <module>
from flask_bcrypt import Bcrypt
File "/home/ff/.cache/pypoetry/virtualenvs/conveyors-SV5d9Vx2-py3.9/lib/python3.9/site-packages/flask_bcrypt.py", line 21, in <module>
from werkzeug.security import safe_str_cmp
ImportError: cannot import name 'safe_str_cmp' from 'werkzeug.security'
In my __init__.py I have
...
from flask_bcrypt import bcrypt
from flask_login import LoginManager
...
and then below in create_app:
def create_app(config_class=Config):
app = Flask(__name__)
app.config.from_object(Config)
db.init_app(app)
bcrypt.init_app(app)
login_manager.init_app(app)
...
I've read Werkzeug release note about safe_str_cmp being removed from Werkzeug 2.1 and needs to be replaced with equivalent hmac functions, but I'm not sure what I need to do in my code to fix this.
Any help greatly appreciated.
Thanks.
It turned out to be a poetry update problem. Whatever I tried it wouldn't upgrade flask_bcrypt to the latest version 1.0.1 and stayed with 0.7.1
I had to start kind of from scratch and do
poetry add flask
...
for every package needed for this app

No module named 'django.contrib.admin.templatetags.admin_static'

my django version is 3.0.5 and django-suit version is 0.2.28 but why does this error happen?
the whole error information is as follows:
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\suit\admin.py", line 8, in <module>
from suit.widgets import NumberInput, SuitSplitDateTimeWidget
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\suit\widgets.py", line 6, in <module>
from django.contrib.admin.templatetags.admin_static import static
ModuleNotFoundError: No module named 'django.contrib.admin.templatetags.admin_static'
I solved the problem.
Modify this fileļ¼š \Python38\Lib\site-packages\suit\widgets.py
# from django.contrib.admin.templatetags.admin_static import static
from django.contrib.admin import static
then rerun your program, maybe met problem below:
File "D:\Work_Station\Python38\lib\site-packages\suit\templatetags\suit_menu.py", line 17, in <module>
string_types = basestring,
NameError: name 'basestring' is not defined
modify the file : Python38\lib\site-packages\suit\templatetags\suit_menu.py
# from django.utils.six import string_types
from six import string_types

ModuleNotFoundError for model class in django

I ran into the following ModuleNotFoundError error.
File "C:\django-project\CodingWithMitchBlog\demoproject\Blog\api\urls.py", line 3, in <module>
from demoproject.Blog.api.views import api_detail_BlogPost_view
ModuleNotFoundError: No module named 'demoproject.Blog'
'Blog' is my appname.
This is my project structure.
This might be due to incorrect import statements used in the files. If the import statements has the projectname prefixed try removing it and run again.
For example change:
from demoproject.Blog.models import ModelClass
to
from Blog.models import ModelClass
in the urls.py file

Django 1.9 and django.contrib.auth

I don't have django.contrib.auth in INSTALLED_APPS, and I don't want to do it because I'm using a custom user model and I don't need none of the builtin User, Group and Permission models.
I was hoping this was possible in Django 1.9, as the docs state in https://docs.djangoproject.com/en/1.9/releases/1.9/ under the django.contrib.auth section that:
AbstractBaseUser and BaseUserManager were moved to a new django.contrib.auth.base_user module so that they can be imported without including django.contrib.auth in INSTALLED_APPS (doing so raised a deprecation warning in older versions and is no longer supported in Django 1.9).
However, as of now I can't import anything from django.contrib.auth without raising errors. No middleware or form can be imported. I have to either add django.contrib.auth to INSTALLED_APPS or don't use anything from that module.
Whenever a model in django.contrib.auth is indirectly imported I get the classic error that: whatever_model_was_indirectly_imported doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.
EDIT: Including last part of the traceback:
...
File "/usr/lib/python2.7/site-packages/django/contrib/auth/middleware.py", line 3, in <module>
from django.contrib.auth.backends import RemoteUserBackend
File "/usr/lib/python2.7/site-packages/django/contrib/auth/backends.py", line 4, in <module>
from django.contrib.auth.models import Permission
File "/usr/lib/python2.7/site-packages/django/contrib/auth/models.py", line 38, in <module>
class Permission(models.Model):
File "/usr/lib/python2.7/site-packages/django/db/models/base.py", line 102, in __new__
"INSTALLED_APPS." % (module, name)
RuntimeError: Model class django.contrib.auth.models.Permission doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.
Any workarounds?
It looks like the only workaround as of now is including django.contrib.auth in INSTALLED_APPS and ignoring the three tables in database.

weird django error: cannot import name get_path_info

I suddenly started getting this error when I try to start the django development server, and I cannot figure out where it is coming from. I have tried updating django.
File "/virtualEnv/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/runserver.py", line 6, in <module>
from django.contrib.staticfiles.handlers import StaticFilesHandler
File "/virtualEnv/lib/python2.7/site-packages/django/contrib/staticfiles/handlers.py", line 9, in <module>
from django.core.handlers.base import get_path_info
ImportError: cannot import name get_path_info
Has anyone seen any error like this before? Definitely trying my best to figure this out...
For me, the problem was that dj_static 0.0.5 didn't seem to be playing nicely with Django 1.7. I upgraded to dj_static 0.0.6 and it fixed it.
I had a similar issue.
Resolved for Django 1.7 by changing the import path for get_path_info:
from django.core.handlers.base import get_path_info
became:
from django.core.handlers.wsgi import get_path_info