Django-grappelli admin: No reverse match error - django

I've been working on a django project for a while now that uses grappelli for the admin and all of a sudden today my change_form.html template is throwing the following error:
Caught NoReverseMatch while rendering: Reverse for "grp_related_lookup" with arguments '()' and keyword arguments '{}' not found.
The offending line of code is line 38:
37 $.each(related_lookup_fields_fk, function() {
38 $("#id_" + this).grp_related_fk({lookup_url:"{% url grp_related_lookup %}"});
39 });
which is preceded by this bit of code:
var related_lookup_fields_fk = {% get_related_lookup_fields_fk adminform.model_admin %};
Obviously it's the {% url grp_related_lookup %} bit that's causing the problem.
I don't understand how the template is resolving grp_related_lookup to grappelli.views.related.related_lookup. I have tried replacing grp_related_lookup with grappelli.views.related.related_lookup and that didn't work either. Also, in the template the offending line looks like this:
$("#id_" + this).grp_related_fk({lookup_url:"{% url grp_related_lookup %}"});
but in the error message it looks like this:
$("#id_" + this).grp_related_fk({lookup_url:"{% url 'grp_related_lookup' %}"});
I don't know if the single quotes surrounding grp_related_lookup might have something to do with the problem or not. Is that how django rendered the function call? Is it passing the string 'grp_related_lookup' to the url template tag? If so, what might have caused this to break suddenly?
Some additional info:
The value of related_lookup_fields is an empty list []. I am not defining any related_lookup_fields in my admin.py.
I threw a couple debug statements into the grappelli.views.related.related_lookup view function and it doesn't appear to be getting called.
I have not touched any of the templates recently.
Hopefully someone can point me in the right direction... Thanks!

Do you still have 'grappelli.urls' included in your URLconf? That the only reason I see that would cause this error. You can try using python manage.py shell:
from django.core.urlresolvers import reverse
print reverse('grp_related_lookup')
If this line returns the correct URL, you shouldn't get a NoReverseMatch in your template.
The quotes around grp_related_lookup shouldn't be a concern. The {% url %} tag accepts both quoted and unquoted strings as first argument, so django normalizes it to quoted strings. This behaviour is going to change in the future: you'll be able to pass template variables to {% url %} using unquoted strings. {% url foo %} and {% url "foo" %} won't give the same result, see the 1.3 release notes for details about this.

I encountered the same behavior with Django 1.5 and Grappelli 2.4.4.
To fix the problem I had to add
url(r'^grappelli/', include('grappelli.urls')),
to urlpatterns.

I faced with this problem today, when I tried to delete data in admin.Reverse for 'app_list' with arguments '()' and keyword arguments '{'app_label': ''}' not found.
I have put the url(r'^grappelli/', include('grappelli.urls')) in urls.py
The solution is pretty strange: just update the grappelli to the latest version. (I updated it from 2.5.6 to 2.6.3)

I faced this problem yesterday. The Django-grapelli I used was the one that was included in the FileBrowser installation. I solved the problem by upgrading Django-grapelli. Just type:
pip install --upgrade django-grappelli

I had a similar issue with urls and noticed that I need
{% load url from future %}
in the template if I want to have quoted url tags. That's also mentioned in the official django documentation: https://docs.djangoproject.com/en/1.3/ref/templates/builtins/#url

I seem to be encountering this same issue, but when I run the suggested console test I get this:
Python 2.7.9 (default, Apr 7 2015, 07:58:25)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from django.core.urlresolvers import reverse
>>> print reverse('grp_related_lookup')
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/Users/tsantor/.virtualenvs/project_env/lib/python2.7/site-packages/django/core/urlresolvers.py", line 579, in reverse
return force_text(iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs)))
File "/Users/tsantor/.virtualenvs/project_env/lib/python2.7/site-packages/django/core/urlresolvers.py", line 496, in _reverse_with_prefix
(lookup_view_s, args, kwargs, len(patterns), patterns))
NoReverseMatch: Reverse for 'grp_related_lookup' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
And my urls.py looks like this:
urlpatterns = patterns(
# Admin
url(r'^grappelli/', include('grappelli.urls')),
url(r'^admin/', include(admin.site.urls), name="admin"),
# main views
#url(r'^$', RedirectView.as_view(url='/admin'), name='home'),
# API
url(r'^api/', include('api.urls', namespace='api')),
)
I also have the latest Grappelli (2.6.4) running on Django (1.8.2). By the way, it seems it only occurs when I try to access and add or edit view. The control panel and list views work.

I added
path('grappelli/', include('grappelli.urls')),
and fixed the problem.

Related

NoReverseMatch at /auth/password/reset/

I am using dj-rest-auth package to do auth related functions, installed the package and added to installed apps and included it in main url as follows
path('auth/', include('dj_rest_auth.urls')),
it works for login, logout etc, but when I do password reset it throws the error
http://127.0.0.1:8000/auth/password/reset/
Reverse for 'password_reset_confirm' not found. 'password_reset_confirm' is not a valid view function or pattern name
NoReverseMatch at /auth/password/reset/
Reverse for 'password_reset_confirm' not found. 'password_reset_confirm' is not a valid view function or pattern name.
Request Method: POST
Request URL: http://127.0.0.1:8000/auth/password/reset/
Django Version: 3.2
Exception Type: NoReverseMatch
Exception Value:
Reverse for 'password_reset_confirm' not found. 'password_reset_confirm' is not a valid view function or pattern name.
Exception Location: /home/biju/Desktop/reporting-system/lib/python3.8/site-packages/django/urls/resolvers.py, line 694, in _reverse_with_prefix
Python Executable: /home/biju/Desktop/reporting-system/bin/python
Python Version: 3.8.10
Python Path:
['/home/biju/Desktop/reporting-system',
'/usr/lib/python38.zip',
'/usr/lib/python3.8',
'/usr/lib/python3.8/lib-dynload',
'/home/biju/Desktop/reporting-system/lib/python3.8/site-packages']
Server time: Fri, 01 Apr 2022 16:01:18 +0000
the urlpattern in https://github.com/iMerica/dj-rest-auth/blob/master/dj_rest_auth/urls.py:
...
path('password/reset/confirm/', PasswordResetConfirmView.as_view(), name='rest_password_reset_confirm'),
...
so you need to change 'password_reset_confirm' to 'rest_password_reset_confirm' in your html url tag or in django function call like reverse()
update:
see https://dj-rest-auth.readthedocs.io/en/latest/faq.html
"You need to add password_reset_confirm url into your urls.py (at the top of any other included urls). Please check the urls.py module inside demo app example for more details."
the package expects something like:
path('password/reset/confirm/<uidb64>/<token>',TemplateView.as_view(template_name="password_reset_confirm.html"),
name='password_reset_confirm'),
path('auth/', include('dj_rest_auth.urls')),
see the demo urls.py: https://github.com/iMerica/dj-rest-auth/blob/24678437b3cdf3fa663880ab66a42aa0992b1d39/demo/demo/urls.py
strange for me that it is mentioned only in the FAQ - looks to me like a bug in the confirm email generation where they use the wrong urlpattern name without the "rest" prefix
.

How to resolve "django.core.exceptions.ImproperlyConfigured: Application labels aren't unique, duplicates: foo" in Django 1.7?

On upgrading to Django 1.7 I'm getting the following error message from ./manage.py
$ ./manage.py
Traceback (most recent call last):
File "./manage.py", line 16, in <module>
execute_from_command_line(sys.argv)
File "/home/johnc/.virtualenvs/myproj-django1.7/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 427, in execute_from_command_line
utility.execute()
File "/home/johnc/.virtualenvs/myproj-django1.7/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 391, in execute
django.setup()
File "/home/johnc/.virtualenvs/myproj-django1.7/local/lib/python2.7/site-packages/django/__init__.py", line 21, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/johnc/.virtualenvs/myproj-django1.7/local/lib/python2.7/site-packages/django/apps/registry.py", line 89, in populate
"duplicates: %s" % app_config.label)
django.core.exceptions.ImproperlyConfigured: Application labels aren't unique, duplicates: foo
What's the problem and how do I resolve it?
The problem is that with the changes to apps in Django 1.7, apps are required to have a unique label.
By default the app label is the package name, so if you've got a package with the same name as one of your app modules (foo in this case), you'll hit this error.
The solution is to override the default label for your app, and force this config to be loaded by adding it to __init__.py.
# foo/apps.py
from django.apps import AppConfig
class FooConfig(AppConfig):
name = 'full.python.path.to.your.app.foo'
label = 'my.foo' # <-- this is the important line - change it to anything other than the default, which is the module name ('foo' in this case)
and
# foo/__init__.py
default_app_config = 'full.python.path.to.your.app.foo.apps.FooConfig'
See https://docs.djangoproject.com/en/1.7/ref/applications/#for-application-authors
I found simple solution for this. In my case following line is added twice under INSTALLED_APPS,
'django.contrib.foo',
Removed one line fixes the issue for me.
I had the same error - try this:
In INSTALLED_APPS, if you are including 'foo.apps.FooConfig', then Django already knows to include the foo app in the application, there is therefore no need to also include 'foo'.
Having both 'foo' and 'foo.apps.FooConfig' under INSTALLED_APPS could be the source of your problem.
Well, I created a auth app, and included it in INSTALLED_APP like src.auth (because it's in src folder) and got this error, because there is django.contrib.auth app also. So I renamed it like authentication and problem solved!
I got the same problem.
Here my app name was chat and in the settings.py , under installed apps i have written chat.apps.ChatConfig while i have already included the app name chat at the bottom. When i removed the chat.apps.ChatConfig mine problem was solved while migrations. This error may be due to the same instance that you might have defined you app name foo twice in the settings.py. I hope this works out!!
please check if anything is duplicated in INSTALLED_APPS of settings.py
This exception may also be raised if the name of the AppConfig class itself matches the name of another class in the project. For example:
class MessagesConfig(AppConfig):
name = 'mysite.messages'
and
class MessagesConfig(AppConfig):
name = 'django.contrib.messages'
will also clash even though the name attributes are different for each configuration.
In previous answer 'django.contrib.foo', was mentioned, but basically adding any app twice can cause this error just delete one (Django 3.0)
for me it was in settings.py
INSTALLED_APPS = [
...
'accounts.apps.AccountsConfig',
'accounts.apps.AccountsConfig',
...
]
just delete one of them
Basically this problem has been created due to duplication of name of installed app in the settings:
This is how I resolved the problem. In settings.py file:
Check the install app in the setting.py if the install app are duplicate
Error shown due to duplication of app name
Remove the duplicate name in the install file
After problem is resolved, you will see interface in your screen
For this I have created application name as polls instead of foo
As therefromhere said this is a new Django 1.7 feature which adds a kind of “app registry” where applications must be determined uniquely (and not only having different python paths).
The name attribute is the python path (unique), but the label also should be unique. For example if you have an app named 'admin', then you have to define the name (name='python.path') and a label which must be also unique (label='my admin' or as said put the full python path which is always unique).
Had same issue, read through the settings.py of the root folder, removed any INSTALLED APPS causing conflict... works fine. Will have to rename the apps names
Need to check in two file
1- apps.py
code something like
from django.apps import AppConfig
from django.utils.translation import ugettext_lazy as _
class ModuleConfig(AppConfig):
name = "ocb.module_name"
verbose_name = _("Module Name")
2 - init.py
code something like
default_app_config = "ocb.users.apps.ModuleConfig"
default_app_config is pointed to your apps.py's class name
in my case, in mysite settings.py , in INSTALLED_APPS array variable I put the name of the app twice by mistake.
I had almost the same issue.
```File "/Users/apples/.local/share/virtualenvs/ecommerce-pOPGWC06/lib/python3.7/site-packages/django/apps/registry.py", line 95, in populate
"duplicates: %s" % app_config.label)
django.core.exceptions.ImproperlyConfigured: Application labels aren't unique, duplicates: auth```
I had installed Django.contrib.auth twice. I removed one and it worked well.
From my experience, this exception was masking the real error. To see the real error (which in my case was an uninstalled python package) comment out the following in django/apps/registry.py:
if app_config.label in self.app_configs:
# raise ImproperlyConfigured(
# "Application labels aren't unique, "
# "duplicates: %s" % app_config.label)
pass
Check for duplicates in INSTALLED_APPS inside the settings.py...If so remove one of it and rerun the command
I had Django==3.2.9 when tried to test my existing Django app on a new environment. I had this exact issue and fixed it by downgrading to Django==3.1.13.
There seems to be an update to applications, check the Django 3.2 documentation for detailed information.
This error occurs because of duplication in your INSTALLED_APPS in settings.py file which is inside your project.
For me, the problem was that I had copy-pasted entire app instead of creating it using command line. So, the app name in the apps.py file was same for 2 apps. After I corrected it, the problem was gone.
In case if you have added your app name in settings.py
example as shown in figure than IN settings.py Remove it and Try this worked for me.
give it a try .
This Worked Because settings.py assumes installing it twice and does not allow for migration
If you want to back older version, command
pip install django==1.6.7

Problems with {% URL %} tag

I've been trying to implement hyper links into my Django application, where a list of items are displayed, clicking on each item will take you to a page detailing more information about the item.
I've been wrestling with the {% URL %} tag and despite searching over here, the internet and books on the matter, I've yet to get it working.
In views.py:
def Link(request):
return render_to_response('Search_Page.html')
In Urls.py:
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'ParkManager.views.home', name='home'),
# url(r'^ParkManager/', include('ParkManager.foo.urls')),
url(r'^test/', Search_Page),
url(r'^search/', Search),
url(r'^details/', Details_Main),
url(r'^Link/(d+}/$', Link),
url(r'^$', 'Parks.views.Link', name="home"),
in my template:
test
Thanks for your time :)
EDIT
error:
The page loads however the link only takes you to 127 .0 .0 .1 /8000
when I add: test
I get:
NoReverseMatch at /search/
Reverse for 'name' with arguments '(u'North West Thrill Centre',)' and keyword arguments '{}' not found.
Request Method:
GET
Request URL:
http://127.0.0.1:8000/search/?search=a&type=parks&submit=Search
Django Version:
1.4.2
Exception Type:
NoReverseMatch
Exception Value:
Reverse for 'name' with arguments '(u'North West Thrill Centre',)' and keyword arguments '{}' not found.
Exception Location:
C:\Python27\lib\site-packages\django\template\defaulttags.py in render, line 424
Python Executable:
C:\Python27\python.exe
Python Version:
2.7.3
Python Path:
['C:\\Users\\User\\Documents\\Django\\ParkManager',
'C:\\Windows\\system32\\python27.zip',
'C:\\Python27\\DLLs',
'C:\\Python27\\lib',
'C:\\Python27\\lib\\plat-win',
'C:\\Python27\\lib\\lib-tk',
'C:\\Python27',
'C:\\Python27\\lib\\site-packages']
Server time:
Mon, 4 Feb 2013 16:05:30 +0000
Error during template rendering
In template C:\Users\User\Documents\Django\ParkManager\Templates\Details_Main.html, error at line 23
Reverse for 'name' with arguments '(u'North West Thrill Centre',)' and keyword arguments '{}' not found.
A clue:
Exception Location:
C:\Python27\lib\re.py in _compile, line 242
Your issue is not related to the url tag. It is a mal-formed regex in your urls.py.
urls.py
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'ParkManager.views.home', name='home'),
# url(r'^ParkManager/', include('ParkManager.foo.urls')),
url(r'^test/', Search_Page),
url(r'^search/', Search),
url(r'^details/', Details_Main),
# LINE BELOW has an open parentheses and not a closed parentheses.
url(r'^Link/(d+}/$', Link),
#url(r'^Link/(d+)/$', Link), #line fixed
url(r'^$', 'Parks.views.Link', name="home"),
unbalanced parenthesis is problem at this line:
url(r'^Link/(d+}/$', Link),
You have forgotten to close the parenthesis.
If you are using {% url %} tag in Django < 1.5, use it this way:
{% load url from future %}
{% url 'namespace:viewname' arg1, arg2 %}
{% url 'namespace:viewname' kwarg1=val, kwarg2=val2 %}
If you are using Django 1.5, you don't have to load the special url tag. If you are not using namespaces (good if you are using general view names like list, detail etc. and you want to distinguish between apps, e.g.: author:list or book:list) use only the view name. Check the documentation, there is a good section about the url tag - https://docs.djangoproject.com/en/1.4/ref/templates/builtins/#url

Error in {% markdown %} and {% textile %} filters in Django Nonrel

I'm having trouble using Markdown in Django Nonrel. I followed this instructions (added 'django.contrib.markup' to INSTALLED_APPS, include {% load markup %} in the template and use |markdown filter after installing python-markdown) but I get the following error:
Error in {% markdown %} filter: The Python markdown library isn't installed.
In this line:
/path/to/project/django/contrib/markup/templatetags/markup.py in markdown
they will be silently ignored.
"""
try:
import markdown
except ImportError:
if settings.DEBUG:
raise template.TemplateSyntaxError("Error in {% markdown %} filter: The Python markdown library isn't installed.") ...
return force_unicode(value)
else:
# markdown.version was first added in 1.6b. The only version of markdown
# to fully support extensions before 1.6b was the shortlived 1.6a.
if hasattr(markdown, 'version'):
extensions = [e for e in arg.split(",") if e]
It seems obvious that import markdown is causing the problem but when I run:
$ python manage.py shell
>>> import elementtree
>>> import markdown
everthing works alright.
Running Markdown 2.0.3, Python 2.7 and latest version of Django Nonrel.
UPDATE: I installed textile and it doesn't work. It produces the same error.
UPDATE 2: This is an issue related with Django Nonrel. I took an older Django project (1.3.1), and works as expected.
Ideas?
Thanks!
Alright, newbie mistake.
Turns out that Django Nonrel couldn't find markdown because for some reason, it wasn't installed in a python path it was looking for. In this case, markdown was installed in /usr/lib/pymodules/python2.7 instead of /usr/local/lib/python2.7/dist-packages/ or some other usual place. So I copied the markdown folder to a place listed by python path, and the error went away.

What would cause a Django template for loop to raise a Key Error?

I upgraded a working Django app to 1.1 and I now get a KeyError exception on a for loop!
Template error
In template /vol/.../templates/base_bbn.html, error at line 7
Caught an exception while rendering: 'django.contrib.comments.urls.'
You would think that there couldn't be a KeyError on a for loop like this because there would be a key for each item it iterates through.
{% block blog_class %}
{% for post in POSTS %} # <-----------Template error on this line
<p class="bbn-dateln">{{ post.publish|date:"Y F d" }
The actual exception is KeyError
File "/usr/lib/python2.5/site-packages/django/utils/importlib.py", line 36, in import_module
return sys.modules[name]
KeyError: 'django.contrib.comments.urls.'
Any suggestions on how to debug this? POSTS that I'm passing to this template to be rendered looks fine....
Ok! I figured it out myself.
It seems that django.contrib.comments.urls in 1.1 now has a dependency on module dateutils that my python environment didn't have. Once I installed dateutils via easy_install, it started working again.
For some reason, the exception this caused bubbled up as a "template error" and "KeyError" on the django error page. It took some time in the python debugger to find the real cause