django can't find the admin directory - django

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

Related

How to fix "django.contrib.gis.geoip2 has no attribute GeoIP2"

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.

ModuleNotFoundError: No module named 'django_tables2'

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

DJANGO: feinCMS missing mptt when trying to sync.db

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.

collectstatic throws 'OSError: [Errno 2] No such file or directory:' on dotcloud

As instructed in the dotcloud tutorial, this is the code in my postinstall:
#!/bin/sh
python createdb.py
python some_project/manage.py syncdb --noinput
python mkadmin.py
mkdir -p /home/dotcloud/data/media /home/dotcloud/volatile/static
ln -sf /home/dotcloud/volatile/static /home/dotcloud/static
python some_project/manage.py collectstatic --noinput
...nginx.conf
location /media/ { root /home/dotcloud/data ; }
...and settings.py
....
MEDIA_ROOT = '/home/dotcloud/data/media/'
MEDIA_URL = '/media/'
STATIC_ROOT = '/home/dotcloud/volatile/static/'
STATIC_URL = '/static/'
....
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',
'some_project',
)
When postinstall is run, this error is thrown:
OSError: [Errno 2] No such file or directory: '/home/dotcloud/rsync-1346498181296/some_project/static'
I've been on it for a long time and its confusing because the documentation says /static/ is already setup by the python service and links to /home/dotcloud/static
Can someone assist? Everything worked well until I got to setting up the app for static content. Django version is 1.4.1 on Python 2.7
After getting some sleep, I discovered that my 'static' folder was not in the location I specified in my 'settings.py' file.
Also, dotCloud has updated their documentation to warn that '/static/' is no longer automatically created as earlier stated so I changed my postinstall script to remove the symlink to '/static/' and also adjusted the nginx.conf file as instructed in the updated documentation.
Reference:
Handlinng static files on dotCloud
Any error messages like "./postinstall failed with return code" means that there is a problem with your own script, not the platform.
In order to debug postinstall executions easily on dotCloud, you can do the following:
Let's assume that your app is "ramen" and your service is "www".
$ dotcloud -A ramen run www
> ~/current/postinstall
It'll re-execute the postinstall but from your session this time, so you'll be able to easily update the postinstall code and re-run it without having to push again and again.
Once you found the root cause, fix it locally and repush your application.

django_nose unit tests fail (no such option)

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