I am trying to retrieve my visitors' location.
After successfully retrieving the IP Adress I want to use
the GeoIP2 object to get information about the location.
https://docs.djangoproject.com/en/2.2/ref/contrib/gis/geoip2/#django.contrib.gis.geoip2.GeoIP2
In my settings.py file I added 'django.contrib.gis.geoip2' to my installed apps:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.gis.geoip2',
'web'
]
Using the shell everything works perfect [python3 manage.py shell]:
dir(django.contrib.gis.geoip2)
['GeoIP2', 'GeoIP2Exception', 'HAS_GEOIP2', '__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', 'base', 'geoip2', 'resources']
However trying to use the GeoIP2 object in my application 'web' I get the error: "django.contrib.gis.geoip2 has no attribute GeoIP2".
['HAS_GEOIP2', '__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__']
There is a dependency mentioned in the documentation you link to, which you are missing on your web server:
In order to perform IP-based geolocation, the GeoIP2 object requires the geoip2 Python library
You need to install this with pip install geoip2.
Note that the documentation also mentions other requirements which you also need to set in order to use this module.
Related
I am trying to use Django-tables2, but my project can't find this module.
Firstly, I installed it without a problem.
(acct) C:\Users\tsjee_000\dev\acct\src>pip install django-tables2
Requirement already satisfied: django-tables2 in c:\users\tsjee_000\dev\acct\lib\site-packages
Requirement already satisfied: Django>=1.11 in c:\users\tsjee_000\dev\acct\lib\site-packages (from django-tables2)
Requirement already satisfied: pytz in c:\users\tsjee_000\dev\acct\lib\site-packages (from Django>=1.11->django-tables2)
Secondly, I added this to 'INSTALLED_APPS' in settings.py
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django_tables2',
'clients',
'companies',
'report',
]
Thirdly, views.py and html templates are updated according to the tutorial.
But when I run my project it doesn't work because of the error,
ModuleNotFoundError: No module named 'django_tables2'
I think this error happens in settings.py.
FYR, 'django_tables2'module can be imported correctly in the shell mode.
Assuming it has been installed correctly, are you sure you have activated your virtualenv? The supplied output above indicates you are using a virtualenv called acct.
Try
pip install django_tables2
I'm trying to setup an instance of FeinCMS to check it out. I've added the all the modules under INSTALLED APPS but when I run the command python manage.py syncdb I get the error Import Error: No module named mptt. What am I doing wrong?
My settings.py:
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'feincms',
'mptt',
'feincms.module.page',
'feincms.module.medialibrary'
)
Did you install the package?
> pip install django-mptt
I assume you're using a virtualenv?
Is your project running within the same Python env as the interpreter? If it is, a quick check would be:
> pip install yolk
> yolk -l # see if the mptt package is available, if not:
> pip install django-mptt # optionally use the --update flag
Still issues? Remove any *.pyc files and restart your server to make sure there's no import issues from previously removed files.
> find . -type f -name "*.pyc" | xargs rm
> ./manage.py runserver 8000
No good? Add a statement to your manage.py file right after your import statements:
# ...
import sys
print sys.path
Re-run the server to see if the mptt is missing from your path, if it is, check your site-packages folder and check the package's path.
I have a new project and can't get django_nose set up correctly. I have never had this problem before. So, makes me think that it's a configuration issue. But, I can't spot it.
I'm using virtualenv and have both nose and django-nose installed. Here is my requirements.txt
Django==1.3.1
distribute==0.6.24
django-nose==1.0
nose==1.1.2
psycopg2==2.4.5
wsgiref==0.1.2
settings.py
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django_nose',
'main',
)
TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'
NOSE_ARGS = [
'--with-spec', '--spec-color',
# Packages to test
'main',
]
With my virtualenv activated, when I run:
python manage.py test
I get the following:
nosetests --verbosity 1 --with-spec --spec-color main
Usage: manage.py [options]
manage.py: error: no such option: --with-spec
Has anybody had this problem? Can someone see what I'm doing wrong?
I figured it out. My fault (as usual). Just for future reference... those are actually not nose arguments and probably shouldn't be in there. They are args for pinocchio.
pinocchio
I'm new to learning django, and I get a 'template does not exist' error when trying to get to the admin site.
All the other answers have said 'django.contrib.admin', wasn't in the settings.py file, but I've checked that and it is there.
I've also checked that the directory exists, it's in
/usr/local/lib/python2.7/dist-packages/django/contrib/admin/templates/admin
the directory of my app is /media/sf_Python/mysite which is in a virtualbox, but I don't know if that is the problem.
Without any entries in my url file, I am able to get the "It worked!" page, so some things are working.
This answer suggests a full reinstall in to your virtualenv, using pip.
pip install -r requirements.txt --ignore-installed \
--force-reinstall --upgrade --no-cache-dir
That worked for me, with Python 2.7.12, pip 9.0.1, and Django 1.4.
The second step of the docs. says:
The admin has four dependencies - django.contrib.auth,
django.contrib.contenttypes, django.contrib.messages and
django.contrib.sessions. If these applications are not in your
INSTALLED_APPS list, add them.
https://docs.djangoproject.com/en/1.3/ref/contrib/admin/
Check the settings.py and then don't forget to run python manage.py syncdb
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
'django.contrib.admindocs',
)
Then, you have to edit the urls.py (it is in the same place as settings.py. Uncomment all the lines that say "uncomment to enable admin". It is a couple of imports and one regular expression.
Then run your server.
This link may help: http://www.djangobook.com/en/2.0/chapter06.html
I'm running django on Dreamhost right now with fastcgi, and I'm getting really weird behavior. First, the server runs Python 2.3. On my computer, I'm running 2.6 and all my source code works. When I put it on my host though, nothing works. Right now, when I pkill python and then load a page, the first error complains about a syntax error at 'class Item_list()' line:
from dtms.models import *
class Item_list():
def __init__(self, list = None, house_id = None):
self.list = list
self.house_id = house_id
def ret_list(self):
return self.list
Then, if I reload it again without changing anything, I get this error:
Django Version: 1.1 alpha 1 SVN-10114
Python Version: 2.3.5
Installed Applications:
['django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.admin',
'mysite.dtms']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware')
Traceback:
File "/home/victor/django/django_src/django/core/handlers/base.py" in get_response
82. callback, callback_args, callback_kwargs = resolver.resolve(
File "/home/victor/django/django_src/django/core/urlresolvers.py" in resolve
184. for pattern in self.url_patterns:
File "/home/victor/django/django_src/django/core/urlresolvers.py" in _get_url_patterns
212. raise ImproperlyConfigured("The included urlconf %s doesn't have any"
Exception Type: ImproperlyConfigured at /dtms/login/
Exception Value: The included urlconf mysite.urls doesn't have anypatterns in it
Any ideas?
class Item_list():
You can't include an empty inheritance list in Python 2.3. There seems to have been a change in the grammar that allows it now but not then.
It would normally be written:
class Item_list:
if you don't want any base classes. But generally these days you'd want to derive from object to get new-style classes.
I don't know much about your deployment environment, but in general when you've tried to import something and got an exception, it can leave behind partially-initialised modules in sys.modules that will frustrate future attempts to import them, resulting in otherwise inexplicable errors where properties and actions of the module are not where they were expected.
In general once an import has failed you should consider the environment lost and start again, but I don't know how your Django deployment copes with errors like that and process-restarting issues. Maybe the original error has left an interpreter running without having written the expected stuff to url_patterns, or something.