NoReverseMatch for all admin urls after upgrade to django 1.7 - django

I am in the process of upgrading huge project from Django 1.6.2 towards latest 1.8 version.
Following all release notes here: https://docs.djangoproject.com/en/1.8/releases/1.7/#using-a-custom-manager-when-traversing-reverse-relations
I believe I revisited my entire project for backwards incompatibilities, but I am still getting this error on any reverse url call to any admin page.
from django.core.urlresolvers import reverse
reverse('admin:scanners_scanner_changelist')
NoReverseMatch: Reverse for 'scanners_scanner_changelist' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
This was working just fine on django 1.6.x
It's very frustrating as this error tells you nothing... Basically you have to guess and try what's wrong. Do any of you guys have some ideas what I might be missing, what is changed from Django 1.6 to 1.7 that could potentially cause this?
All other urls work fine except for admin changelist and change urls.

Finally figured this out. django-adminplus was a cause of this.
So if you are having similar problems when upgrading from Django 1.6.x to 1.7.x try to change django.contrib.admin to django.contrib.admin.apps.SimpleAdminConfig and do not remove admin.autodiscover() from your main urls.py file. This way you are doing admin discovery manually and explicitly, the old way instead of new implicit method which might cause you troubles if you are doing some serious hacking within your project.
Cheers!

Related

Django Upgrade from 1.11 to 2.2.1 Problem with URLs and Paths

Today I decided to upgrade my project from Django 1.11 to 2.2.1. I've been working through various issues with my project, and I'm fighting through them. However, I spent most of tonight trying to get the URLs to work and they won't cooperate. Long story short, I have multiple app in my project and each app has a URL with it's own namespace. In Django 1.11 this is working fine. However, when I try to port the logic over to Django 2.2.1, I keep getting an error saying that I have a circular import somewhere probably.
Here is a snippit of what works just fine in Django 1.11.......
My Main Project...In Django 1.11
url(r'^Main/',include('AppA.urls',namespace="AppA")),
But when I try to do this in Django 2.2.1.....
I realize that URLs were replaced by paths...
path('', include('AppA.urls')),
But when I try to start my application it says....
your project does not appear to have any patterns in it. If you see valid p
atterns in the file then the issue is probably caused by a circular import.
I can't seem to figure out how to create the namespace that is working in django 1.11 so that I can properly reference my urls in my templates.
I've been staring at this most of the evening and that might be why I'm not seeing it...I also looked at the Django doc...https://docs.djangoproject.com/en/2.2/topics/http/urls/
And I just can't see what I might be doing wrong. Thanks in advance for any help to get me back on track.
As Bloodmallet pointed out to me...
I needed to add....
app_name = 'Appa'
to the top of my urls.py file. After doing this, the path URL worked as expected.
Instead of path(), consider using re_path():
from django.urls import include, re_path
re_path(r'^Main/',include('AppA.urls',namespace="AppA")),

Invalid URL pattern using Django with Mezzanine

I'm relatively new using Mezzanine and Django. But I run the manage.py with runserver as a parameter and I get the following error.
ERRORS:
?: (urls.E004) Your URL pattern (u'^', (<module 'mezzanine.urls' from
'C:\Users\khirst\InovaSupportSiteIsolated\lib\site-packages\mezzanine\urls.py'>, None, Non
e)) is invalid. Ensure that urlpatterns is a list of url() instances.
HINT: Try using url() instead of a tuple.
I browsed through Mezzanine's urls.py, and it seems to be properly updated for the new urlpatterns standards. I am using Django 1.10.0, and Mezzanine 4.2.2.
There are several lines that use
urlpatterns += [url("^", include("..") ..
of some sort. I am guessing that
means that for every url, add the following module as a possible match. It seems that Django doesn't like one of these. I can't find any help with this on Mezzanine's site or otherwise. Supposedly this version of Mezzanine and Django are supposed to be compatible. Has anyone else encountered this?
I blamed mezzanine, but it was our fault in our base module.
We had a tuple in our urls file.
("^", include("mezzanine.urls"))
That needed to be
url("^", include("mezzanine.urls"))
But Django was complaining as if it was in mezzanine's code.

Django 1.7 tutorial: Use generic views

I need to use Jython instead of Python, I found that jython2.7b2 works with DJango 1.7. So, I am stuck using the beta version. I am trying to follow the current Django tutorial and I have ran into a problem. I am not sure if I am using generic views properly. When I try to change the urls.py (polls) file. I see that pydev complains that views.IndexView, views.DetailView, and ResultsView don't exist. Am I doing something wrong? Or did they change the way generics work in version 1.7?
My System:
Windows 7
jython2.7b2
Django-1.7c3
postgresql-9.3.5-1-windows-x64
postgresql-9.3-1102.jdbc41.jar
Here is the url for the tutorial, go to the section "Use generic views: Less code is better"
Django tutorial part 04
Once you have changed your urls.py, you need to define the new views.
This is covered in the next section of the tutorials, Amend views.

Installed Django app (registration) not using main urls.py for tests

I'm not sure if this is a bug with django-registration or what I'm doing.
I have a bare minimum project, with django-registration installed and no apps of my own. Django-registration requires a few templates, so I have them in templates/registration. In each template, I have a template tag {% url index %}, which is included in my urls.py.
By running ./manage.py test registration --failfast, I get:
TemplateSyntaxError: Caught NoReverseMatch while rendering: Reverse for 'index' with arguments '()' and keyword arguments '{}' not found.
My own template isn't seeing my url entry.
I debugged into Django's reverse function, and it seems as though my urls.py isn't being used at all. Instead registration.tests.urls.py is used.
Is this the intended behavior? I'm hoping not, since I can't get basic tests to pass. How do I get around this?
This is a bug in django-registration. This blog article describes the problem and a workaround.

django-debug-toolbar with django-cms and Django 1.3

I keep hitting an error when trying to use django-debug-toolbar and django-cms together.
"MpttMeta has no attribute 'class'"
I have a feeling it's something to do with the Mptt app bundled with Django CMS, but I'm not sure, and I've seen this on a few projects but I'm surprised I can't find a direct hit for the error message in Google so I thought I'd post here.
I've tried using latest released version of debug toolbar, also the develop branch, and also dcramer's fork, but it's making no difference. I'm on Django 1.3 and Django CMS 2.1.3.
Any ideas?
Thanks!
The problem is that django-debug-toolbar expects the MpttMeta class needs to be a 'new style' class, which is a fairly straightforward patch (line 33 in django-cms/publisher/mptt_support.py). Change:
class MpttMeta:
to
class MpttMeta(object):
In Django-CMS 2.1.3, they still have their own monkey-patched mptt bundled with Django-CMS. In the next release of Django-CMS will no longer bundle its own mptt and will instead rely on the independently developed package.
It could be any problem related to Django 1.3.
Django CMS 2.1.3 supports only 1.2.X branch: http://docs.django-cms.org/en/2.1.3/getting_started/installation.html#requirements
Jonas Obrist, Django CMS dev says "Maybe a minor version of
2.1 will add official 1.3 support"
Or you can put this in yours .... urls.py for example. Not in settings.py because project will not start.
from publisher.mptt_support import MpttMeta
if not hasattr(MpttMeta, '__class__'):
MpttMeta.__class__ = type
Caught AttributeError while rendering: class MpttMeta has no attribute '__class__'
I believe this had to do with the way the MPTTMeta class is loaded into the metaclass (MPTTModelBase) making it not have a class attribute.
A monkeypatch fix is to wrap the offending statement in django-debug-toolbar like so:
try:
text = "method %s on %s object" % (receiver.__name__, receiver.im_self.__class__.__name__)
except:
text = "method %s on %s object" % (receiver.__name__, type(receiver.im_self).__name__)
This changes the output slightly to become
method finish_mptt_class on classobj object
Clearly not a permanent fix, but it gets you the debug-toolbar + django-cms working.