Django-Bleach or Just Bleach? - django

I've recently tried to implement Django-Bleach into my project, but I'm having an issue with an import library. I am currently running Python 3.6.2 and Django 1.11. When I try to define a django_bleach form in my forms.py, with the following statement:
from django_bleach.forms import BleachField
I am receiving the following error:
ModuleNotFoundError: No module named 'django.utils.importlib'
I spent the better part of this afternoon researching this error and I have come to understand that the django.utils.importlib statement was deprecated in 1.9. However, I can't seem to determine a workaround for this problem. I did try the suggestion outlined in this issue but it didn't seem to make a difference. I still receive the error. Cannot import importlib
I'm also wondering if I should be using bleach instead of django-bleach as django-bleach doesn't seem to be updated since 2014. Thanks in advance for your suggestions and help.

Package you are trying to use doesen't seem to be maintained.
Error you are facing is related to the forms.py line 7
from django.utils.importlib import import_module
If you are really into the following wrapper package you could fork/fix it and install your forked version instead

Ultimately wound up incorporating just bleach into my django installation. It appears django-bleach is no longer supported for Python 3. Using Bleach and incorporating it according to the documentation allowed me resolve this issue.

Related

django-datatable-view==0.9.0 Django 3.1.3: ImportError: cannot import name 'get_datatable_structure'

I am using the latest package django-datatable-view 0.9.0 in django 3.1.3 (upgrading from django 1.8.6)
When a I run manage.py run server I get the following error:
File "/mcvitty/mcvitty/customers/views.py", line 14, in <module>
from datatableview.utils import get_datatable_structure
ImportError: cannot import name 'get_datatable_structure'
Upgrading the package is not an option as I am already using the latest package. I have searched datatableview get_datatable_structure but I cannot find it. What can I do to fix the error? Thank you for your help
There's a pending PR for that package to fix things for Django 3.1. https://github.com/pivotal-energy-solutions/django-datatable-view/pull/246
You'll need to either
wait until that is merged and a new version released, or
fork the project, merge the fixes you need, bump the version, and use that patched version as a requirement (e.g. https://github.com/YOURGITHUBUSERNAMEHERE/django-datatable-view/archive/master.zip#egg=django-datatable-view)

ModuleNotFoundError: No module named 'textencoder' error when upgraded to python 3

Currently I have migrated my python2 django project to python 3 & after conversion to py3 I am getting below kind of error for below code.
from hubarcode.code128 import Code128Encoder
encoder = Code128Encoder(pur_num, {'is_reliable': False})
Trackeback is as below.
from hubarcode.code128 import Code128Encoder
File "D:\my_project\venv\lib\site-packages\hubarcode\code128__init__.py", line 16, in
from textencoder import TextEncoder
ModuleNotFoundError: No module named 'textencoder'
I have tried to search for solution online on google but not able to solve it.
Any suggestions ?
Thanks.
I am able to solve issue by using pyStrich.
First you need to install pyStrich using pip3 install pyStrich and after thatn
What you need to do is just replace from hubarcode.code128 import Code128Encoder with
from pystrich.code128 import Code128Encoder.
I hope it may help others who have been facing same kind of problem.
pip freeze will show it if you have this module installed in your venv
pip install textencoder to resolve problem

how do i fix "No module named 'win32api'" on python2.7

I am trying to import win32api in python 2.7.9. i did the "pip install pypiwin32" and made sure all the files were intalled correctly (i have the win32api.pyd under ${PYTHON_HOME}\Lib\site-packages\win32). i also tried coping the files from C:\Python27\Lib\site-packages\pywin32_system32 to C:\Python27\Lib\site-packages\win32. I also tried restarting my pc after each of these steps but nothing seems to work! i still get the error 'No module named 'win32api''
Well, turns out the answer is upgrading my python to 3.6.
python 2.7 seems to old to work with outside imports (I'm just guessing here, because its not the first time I'm having an import problem)
hope it helps :)

Can't load Python module by its path - __import__ says ImportError: Import by filename is not supported

I'm far from Python expert, so please bear with me.
I'm using Slack python bot library, which utilizes module loading to execute users code.
I noticed a weird thing - when I launch my script, it says ImportError: Import by filename is not supported on a line self.module = __import__(name) (where name is relative path to the Python file). I don't quite understand the problem, because the owners of the library test their code with both 2.x and 3.x Python, and it DOES work on TravisCI.
I'm using Python 2.7.8 on Windows 7.
How do I fix the problem? I suspect something on my system is wrong. I read similar questions on SO and worked around the issue by using imp.load_source, but I would like to get to the bottom of it.
P.S. It also works if I upload it to Heroku, which by default runs 2.7.12

ImportError: cannot import name update_all_contenttypes

I upgraded recently to Django 1.8. In previous versions of Django, the following import was fine:
from django.contrib.contenttypes.management import update_all_contenttypes
But update_all_contenttypes appears to have been silently removed in Django 1.8 (it was there in 1.7.7). I'm not seeing anything in the 1.8 release notes about its removal... Does anyone know what the modern replacement is for that function?
It's unclear why that function was removed in 1.8, but it appears that the modern replacement is to just re-invent that wheel:
from django.apps import apps
from django.contrib.contenttypes.management import update_contenttypes
def update_all_contenttypes(**kwargs):
for app_config in apps.get_app_configs():
update_contenttypes(app_config, **kwargs)
It seems django team has removed the update_contenttypes function without a mention in the release notes because isn't a documented, public API. (as the said here: https://code.djangoproject.com/ticket/28092)
Now you can use instead the new function create_contenttypes, as you can see here:
https://github.com/django/django/commit/6a2af01452966d10155b720f4f5e7b09c7e3e419
Go to the location of 'django.contrib.contenttypes' in your system (check your 'site-packages' folder of python)
Open the app.py (You can use vi app.py in a terminal window)
Replace 'update_contenttypes' with 'create_contenttypes'
Save the file ('ESC', ‘:’ and ‘wq’ - in a vi editor)
Then try to run the server
create a virtual environment and the error will vanished.
find here how to create a virtual_env: