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

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.

Related

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.

NoReverseMatch for all admin urls after upgrade to django 1.7

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!

How do you use reverse_lazy with function based views in django?

When I run my django app on a production server, I receive an error stating that my urlconf does not contain any patterns. After a few hours of research, I discovered that my problem was mainly due to url template tags that were attempting to do a reverse lookup on the urlconf before the urlconf loaded. This always resulted in an error.
I think that reverse_lazy might solve this issue, as it'd force the urlconf to be loaded first, but I don't know how to apply this to function based views, as the solutions I found online only applied to Class based generic views. Is there a way to fix this problem using reverse_lazy? Or should I try something else?
def myview(request):
return HttpResponseRedirect(reverse('arch-summary', args=[1945]))
from the docs here: https://docs.djangoproject.com/en/1.6/ref/urlresolvers/ shows this usage for reverse. I've never tried it with reverse_lazy, but worth a shot.

How to reverse/name urls with TemplateView.as_view?

I'm trying to use TemplateView.as_view() in urls.py then name it using ye olde templatetag url. Should this work? Or am I just doing it wrong..? Or is it some of the legacy crap in my app interfering? I've got...
<li>Terms and Conditions</li>
and
url(r'^legal/$', TemplateView.as_view(template_name="legal.html"), name="legal"),
Which yields
NoReverseMatch at /how-it-works/
Reverse for '"legal"' with arguments '()' and keyword arguments '{}' not found.
Seems to me this ain't ever gonna work this way.
How do we reverse urls with TemplateView?
The code you have posted is syntactically correct, but there is something else interfering.
That url tag is Django 1.5+ syntax (note the warning in the docs here), can you confirm that is the install you are using? I suspect this is the the problem, the double quoting of legal in the exception message is very suspicious. A Django 1.5+ exception message would contain 'legal', not '"legal"' for a URL that is not found by the dispatcher.
Is the url being registered by the URL dispatcher? You can tell in debug mode by hitting a bad URL (ie 404), the output will list all valid url paths from your URLConf.
Add more info if you continue to have problems so we can isolate further.
Good luck!

django admin colon syntax in template tags and in reverse function

While learning with Django by Example, I have found something I don't yet know and haven't found any reference for it. I'm sure it is well documented somewhere, but I haven't found out how to search for it. Also, I apologize if I'm reasking an already answered question, I haven't found it here either.
What I would like to understand is the "admin: ..." syntax, which I met in several contexts:
In a template .html file:
Add Todo items
In a view function:
return HttpResponseRedirect(reverse("admin:todo_item_changelist"))
I have gone through the djangoproject tutorial and the first 8 chapters of djangobook, and I didn't meet it there. I know, though, that in a reverse function a view function may be passed, and that {% %} template tags 'do something', but I have only seen dotted syntax used for these cases, so far. May it be that for referencing admin features, instead of the dotted syntax, we use this colon?
I would really appreciate some brief explanation on what it does.
It's URL namespace. Admin docs:
https://docs.djangoproject.com/en/2.2/ref/contrib/admin/#admin-reverse-urls, general URL namespace docs: https://docs.djangoproject.com/en/2.2/topics/http/urls/#url-namespaces.
from django docs:
If you'd like to retrieve a namespaced URL, specify the fully qualified name:
{% url 'myapp:view-name' %}
This will follow the normal namespaced URL resolution strategy, including using any hints >provided by the context as to the current application.