Hi there I am receiving a strange error that I haven't been able to fix. I posted a question on StackOverflow but I will also post here in hopes that someone may be able to point me in the right direction.
I am using the Django-Tables2-Column-Shifter Django library successfully in my Django application from one of my applications named app1. I am running into a bizarre error when attempting to use the same logic to use Django-Tables2-Column-Shifter from another app app2 which uses a different model. The error that I am receiving is below:
File "/home/datavizapp/.virtualenvs/venv/lib/python3.9/site-packages/django/utils/module_loading.py", line 17, in import_string
module = import_module(module_path)
File "/usr/local/lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 972, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 984, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'project_name'
The code posted below all works as expected. The error arises in the get_table_class code when I change the following:
from project_name.app1.models import Table1
from project_name.app2.models import Table2
from project_name.app2.tables import get_table_1_class
from project_name.app2.tables import get_table_2_class
#from project_name.app1.tables import get_table_1_class # This also works if uncommented (original code is in app1)
from django_tables2_column_shifter.tables import (
ColumnShiftTableBootstrap4
)
from django.contrib.auth import get_user_model
User = get_user_model()
from django.views.generic import TemplateView
from django_tables2.config import RequestConfig
class Base(object):
container_css = "span10 offset1"
template_name = "cryptoscreener/shifter-template.html"
table_class_version = ColumnShiftTableBootstrap4
def get_context_data(self, **kwargs):
context = super(Base, self).get_context_data(**kwargs)
# Build tables
tabledata_queryset = Table1.objects.all()
#tabledata_queryset = Table2.objects.all() # This works fine
# Below is where the error is triggered. This code below works but if I change it to get_table_2_class I see the error
tabledata_table = get_table_1_class(
self.table_class_version
)(tabledata_queryset)
# Turn on sorting and pagination
RequestConfig(self.request, paginate={'per_page': 20}).configure(tabledata_table)
context['container_css'] = self.container_css
context['tabledata_table'] = tabledata_table
context['tabledata_queryset'] = tabledata_queryset
class Bootstrap5(Base, TemplateView):
container_css = "col-xs-10 col-xs-offset-1"
template_name = "cryptoscreener/shifter-template.html"
table_class_version = ColumnShiftTableBootstrap4
Below is "tables.py" inside app2
from project_name.app1.models import Table1
def get_table_1_class(TableClass):
class Table1Class(TableClass):
class Meta:
model = Table1
return Table2Class
# The error appears when calling get_table_2_class from views.py in app2
from project_name.app2.models import Table2
def get_table_2_class(TableClass):
class Table2Class(TableClass):
class Meta:
model = Table2
return Table2Class
Hi.
Could you give more info about which versions of Django and others libs you use?
In first moment, it looks like not supported version of some lib -> If in one project it works but in second not.
Hi there I am receiving a strange error that I haven't been able to fix. I posted a question on StackOverflow but I will also post here in hopes that someone may be able to point me in the right direction.
StackOverflow Link
I am using the Django-Tables2-Column-Shifter Django library successfully in my Django application from one of my applications named app1. I am running into a bizarre error when attempting to use the same logic to use Django-Tables2-Column-Shifter from another app app2 which uses a different model. The error that I am receiving is below:
The code posted below all works as expected. The error arises in the get_table_class code when I change the following:
to
Below is "views.py" inside app2
Below is "tables.py" inside app2
Below is the template "shifter-template.html"
I hoping someone has a solution or a suggestion on how I may further troubleshoot this problem. Thanks for taking the time out of your day to review.