Weird django admin importerror - python

I am getting a weird import error when I try to access admin: http://dpaste.com/292489/ It doesn't seem to be related to my code and I have setup all the proper admin settings and urls, since admin has worked properly before.

The only thing I think to do is to double check your PYTHONPATH and triple check that your ROOT_URLCONF is pointing to the right spot.

Related

How is django's default root homepage rendered?

This is a kind of want-to-know itch. Many questions here ask how to replace the default Django homepage (e.g. ). I understand that issue. What I'm curious to know is how the default page is rendered when a new project is created (i.e., in debug mode). Even though my question is not as directly practical as knowing how to replace the default homepage, I have the feeling that if I figure it out, I may understand how Django works a bit better.
I would expect it to be in the default urls.py file, but the only entry by default in urlpatterns of urls.py is path('admin/', admin.site.urls). My first naive expectation would be an entry in urlpatterns that you could remove or comment out. Since there's nothing there besides admin/, I'm guessing there's some other built-in app or middleware that specifies the default homepage, but I don't know where to look.
Here's my progress in understanding this so far:
Commenting out DEBUG=True in settings.py causes the default homepage to no longer appear.
I've seen this documentation about how Django processes requests, which mentions middleware that can set the urlconf attribute on a request that changes the default, ROOT_URLCONF.
So far Django has been pretty straightforward, but this seems like something magical, so I'm trying to figure out what's going on behind the scenes.
I appreciate the help!
The relevant code is here. Django basically has a special case for when no matching URL is found in the URL configuration, and the requested path is /, and there is only one entry in the URL configuration.
In that case it loads a default_urlconf which renders that welcome template in place of a regular 404 response.
This is called from inside the technical_404_response function, which is only called when DEBUG=True.

django geoposition map doesn't appear in admin

I'm using django-geoposition in a project and added it to my admin with a GeopositionField() in my models.py.
class MyClass(models.Model):
position = GeopositionField()
When I access it, it shows the lat, long field, but not the google map.
There are no errors in the browser console.
I have the application configured correctly in settings.py: INSTALLED_APPS and GEOPOSITION_GOOGLE_MAPS_API_KEY.
Django version==1.11.5
What can cause this?
It's a django-geoposition problem.
I found it and a workaround in:
https://github.com/philippbosch/django-geoposition/issues/83

Django admin unregister Sites

I've been trying to unregister the admin for sites in django by doing the following:
from django.contrib.sites.models import Site
admin.site.unregister(Site)
However this gives me an error stating that "Site" is not registered (even though it showed up in admin before).
If I try doing the following I get no errors but "Site" stays in the admin:
from django.contrib.sites.models import Site
admin.site.register(Site)
admin.site.unregister(Site)
I need the sites app and cannot take it out of INSTALLED_APPS in settings. However the admin for it is utterly useless to me.
Any ideas on what I am doing wrong here?
Thanks!
The order of your INSTALLED_APPS setting is important.
When Django starts it will import the applications in INSTALLED_APPS in the order they are defined (https://docs.djangoproject.com/en/1.11/ref/applications/#how-applications-are-loaded). In your example above you were unregistering Site before Django had the chance to register is it.
There isn't much you can do in terms of troubleshooting except for reading the logs very carefully. After staring at them for a while you either become one with Django and understand it all, or you come here like the rest of us ;-)
My INSTALLED_APPS usually start with the django.contrib apps, then any 3rd-party applications, then my apps at the bottom. I only change this if I have a very good reason to.

Django: new project keeps looking for a settings folder

So I started a new django project on a system that has another project. I use subdomains and mod_wsgi to handle the direction to the various projects. The direction seems to be working just fine.
For some reason, though, this second project is insist my urls.py and settings.py files should be located at settings/urls.py and settings/settings.py. Any ideas? It completely ignores the perfectly valid urls.py file that's sitting there (with a couple of filters as test urls). It also ignores any urls.py files I actually put at settings/urls.py (as a test). I made ROOT_URLCONF='urls' as opposed to ROOT_URLCONF='projectname.urls' as django never seems to like the former.
Anyway, I'm completely stumped, and after a couple of hours searching through everything, I can't for the life of me figure out where I should even look. Any ideas?
First, I think your problem might actually be that you have ROOT_URLCONF set to urls instead of <proj_name>.urls so it is searching for settings.urls.py because your ROOT_URLCONF tells it to go to urls.py which would be settings.urls.py while in the settings module.
Second, in your wsgi file, do you have the following line:
s.environ['DJANGO_SETTINGS_MODULE'] = 'settings'

Django blows up with 1.1, Can't find urls module

EDIT: Issue solved, answered it below. Lame error. Blah
So I upgraded to Django 1.1 and for the life of me I can't figure out what I'm missing. Here is my traceback:
http://dpaste.com/37391/ - This happens on any page I try to go to.
I've modified my urls.py to include the admin in the new method:
from django.contrib import admin
admin.autodiscover()
.... urlpatterns declaration
(r'^admin/', include(admin.site.urls)),
I've tried fidgeting with paths and the like but nothing fixes my problem and I can't figure it out.
Has something major changed since Django 1.1 alpha -> Django 1.1 beta that I am missing? Apart from the admin I can't see what else is new. Are urls still stored in a urls.py within each app?
Thanks for the help in advance, this is beyond frustrating.
I figured it out. I was missing a urls.py that I referenced (for some reason, SVN said it was in the repo but it never was fetched on an update) and it simply said could not find urls (with no reference to notes.urls which WAS missing) so it got very confusing.
Either way, fixed -- Awesome!
try this:
(r'^admin/(.*)', admin.site.root),
More info
What is the value of your ROOT_URLCONF in your settings.py file? Is the file named by that setting on your python path?
Are you using the development server or what?

Categories