i am having an import error django_tables.
Could not import ikapp.views.admin. Error was: No module named django_tables.
It looks like ikapp.views.admin requires django-tables. Unfortunately it's not possible to tell which version/fork it requires, but it's likely to be either:
https://github.com/miracle2k/django-tables
https://github.com/bradleyayers/django-tables2
django_tables requires that you actually be running within the django-"primed" python environment. You can access this by going to your project's directory and typing
python manage.py shell
Then you can import django_tables with no problems.
For further info, take a look at the following: https://docs.djangoproject.com/en/dev/ref/django-admin/
Related
I am running some python scripts which pertains with a django application.
So I manually made a folder (named scripts) that contains some python scripts but is not made using ./manage.py startapp scripts. Along with this folder there is a modelsapp django app (which contains my models) and then project folder containing settings.py and urls.py.
I run ./manage.py shell < scripts/script.py to run my script.
Now here is a sample code of my scripts.py
from modelsapp.models import *
print(Room.objects.all())
This works pretty well. Now consider a second case. I now just run ./manage.py shell and then put the following commands-
>>>from modelsapp.models import *
>>>def init():
... print(Room.objects.all())
...
>>>init()
This also works pretty well. But now when I run the above code through the file in the first case, it says NameError: name 'Room' is not defined
It looks like the model classes which I just imported aren't accessibly inside a function.
This behavior is a bit weird.
Please help. In case I missed anything to mention, do comment below.
Edit: Since this is a bit weird behavior and am not able to find any answers to it, I am just going to pass the class Room directly to the function init() as a parameter to get the work done as of now.
after you run the django shell, you can run your script with:
>>>execfile('filename.py')
if you want to run it in a normal python shell (not using python manage.py shell) you have to do:
import django
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project(name.settings")
django.setup()
Here's my code configuration:
__init__py
./module_1/foo.py
./module_1/__init__.py
./module_2/bar.py
./module_2/__init__.py
My goal is to be able to import the foo module from bar.py, but I'm getting quite confused on how to do it.
Something such as:
from ..module_1.foo import *
Will raise the following error:
ValueError: Attempted relative import in non-package
EDIT:
Ideally I'd like to be able to run my script in the following fashion:
python ./module1/foo.py
You haven't shown how you are invoking the script, but you need to ensure that your scripts are actually packages in your python path. That's basically what the error message is telling you, you were trying to import a "non-package". You probably don't have your top-level in the python path. For example ...
If your top-level module is called app and your configuration is
<path-to-app>/app/__init__py
<path-to-app>/app/module_1/foo.py
<path-to-app>/app/module_1/__init__.py
<path-to-app>/app/module_2/bar.py
<path-to-app>/app/module_2/__init__.py
You can run your script as follows.
cd <path-to-app>
PYTHONPATH=$PWD python -m app.module_2.bar
Works for me.
I am trying to create a tests folder in my django app.
My app has following structure:
myapp
myapp/tests/__init__
mtapp/tests/test_email
myapp/function
Now i am trying to import function inside test_email file.
and executing test case as
python manage.py test myapp
but this gives me error No module named function.
Please let me know the reason behind this.
First Edit: if i put "import ..function" then its working fine. but is it a right way to do it.
Note: I am using python version 2.7,
Django version 1.5.5
It might be a case of some Cyclic import when you are using from ...filename import function.
It can be resolved by importing the function locally in the TestCase.
I'm trying to get an existing Django project to work on my mac.
I managed to configure everything and opening the project in PyCharm.
When I run I get the error:
TemplateSyntaxError at /
Caught BundleError while rendering: 'stylesheets' not found (using staticfiles finders)
We use Django 1.3 and Webassets 0.7 (just updated from earlier versions).
I have an assets.py defined in my application folder defining the various bundles.
Any suggestions on solving this?
EDIT: Ok, a bit further ... I added my project.assest to settings and now I don't have the Bundle error. I do still have another problem:
Caught BundleError while rendering: 'styles/libs/jquery-ui-timepicker-addon.css' not found
Path look ok, collectstatic works, copies, file is in place ...
any suggestions?
A project-wide assets.py (as opposed to one in an app-directory) is no longer automatically read, you need to define such files through a ASSETS_MODULES setting now.
If you are using staticfiles, pay attention to the fact that the staticfile finders will not be used unless Django is in debug mode (settings.DEBUG=True). In production mode, webassets will assume that collectstatic has been run first.
In settings.DEBUG=True mode, the reverse is true: ONLY the Django staticfile finders will be used. You could try opening a shell (./manage.py shell) and see if the following finds your file:
from django.contrib.staticfiles import finders
finders.find('styles/libs/jquery-ui-timepicker-addon.css')
If it does, then so should webassets.
I had a similar error arise
'[BUNDLE_NAME]' not found (using staticfiles finders)
This wasn't a very helpful message, so ended up looking into ./manage.py shell and running
>>> from django.conf import settings
>>> from [ASSETS_FILE_PATH.assets] import [BUNDLE_NAME]
>>> [BUNDLE_NAME]
If this isn't there it may give you another message.
Everything works as supposed to on the Django development server. In Apache, the django app also works except when matplotlib is used. Here's the error I get:
No module named multiarray.
Exception Type: ImportError
Exception Value: No module named multiarray
Exception Location: /usr/share/pyshared/numpy/core/numerictypes.py in <module>, line 81
Python Executable: /usr/bin/python
Python Version: 2.6.4
From the python shell, both statements work: import numpy.core.multiarray and import multiarray. Any ideas?
Thanks
As I'm looking over the numpy files, I found the multiarray module, which has an extension of 'so'. My guess, is that mod_python is not reading these files.
Problem solved. Here's what I did.
First of all, before I was getting the import error:
"No module named multiarray."
I was getting an error like this:
": Failed to create /some/dir/.matplotlib; consider setting MPLCONFIGDIR to a writable directory for matplotlib configuration data"
By adding the pyshared folder to the PythonPath variable, this error went away and I got the import error.
So here's how I fixed it:
Removed the pyshared folder from the PythonPath variable.
Before importing the matplotlib module, add these lines:
import os
os.environ['HOME']='/some/writable/dir'
Next, before import matplotlib.pyplot or pylab, add these lines:
import matplotlib
matplotlib.use('Agg')
# 'Agg' or whatever your backend is.
This is documented here.
That's is! It's working on python2.5 for me now. But I believe it'll work on 2.6 as well.
On Win32 I solved a similar problem (not being able to load pyd modules through ISAPI_WSGI (IIS)) by downgrading from py2.6.5 to py2.5. It seems like this might be a Python bug that has been re-introduced. See for example this discussion.