NoReverseMatch error in Django [Pinax] - django

My Django project based on pinax-social fails loading any page which has {% url home %} in it, and shows this:
NoReverseMatch at /account/login/
Reverse for 'home' with arguments '()' and keyword arguments '{}' not found.
Hardcoding the url fixes the problem, and only the home ReverseMatch fails.
Here's my urls.py:
from django.conf import settings
from django.conf.urls import patterns, include, url
from django.conf.urls.static import static
from .views import *
from NEOreka.models import *
from .forms import SignupForm
from django.views.generic.simple import direct_to_template
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns("neo.views",
url(r"^neo/(?P<neo_id>\d+)/$", "neo_info"),
)
urlpatterns += patterns("",
url(r"^$", "neo.views.home"),
)
urlpatterns += patterns("",
url(r"^admin/", include(admin.site.urls)),
url(r"^account/signup/$", SignupView.as_view(), name="account_signup"),
url(r"^account/", include("account.urls")),
)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Could someone tell me how I could fix this?

Ok I test this one and it works. I hope it will works also in your side.
{% url neo.views.home %}

Related

Preview custom 500 error page in Wagtail?

I've made custom 500 and 404 error pages in Wagtail. I can preview the 404 page by typing in a false url. I'm just wondering how I can preview the 500 page?
The custom page has links to static images that I need to check are working.
My urls.py
from django.conf import settings
from django.conf.urls import include, url
from django.conf.urls.static import static
from django.contrib import admin
from wagtail.contrib.sitemaps.views import sitemap
from wagtail.admin import urls as wagtailadmin_urls
from wagtail.core import urls as wagtail_urls
from wagtail.documents import urls as wagtaildocs_urls
admin.autodiscover()
urlpatterns = [
url(r'django-admin/', admin.site.urls),
url(r'^admin/', include(wagtailadmin_urls)),
url(r'^documents/', include(wagtaildocs_urls)),
url(r'^sitemap\.xml$', sitemap),
url(r'', include('puput.urls')),
url(r'', include(wagtail_urls)),
]
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
if 'debug_toolbar' in settings.INSTALLED_APPS:
import debug_toolbar
urlpatterns += [
url(r'^__debug__/', include(debug_toolbar.urls)),
]
The answer at https://stackoverflow.com/a/24660486/823020 has most of these details. You can make a view that raises a 500 error.
You can add a views.py to any app. In that file (taken directly from the linked answer):
from django.http import HttpResponseServerError
def my_test_500_view(request):
# Return an "Internal Server Error" 500 response code.
return HttpResponseServerError()
Supplement this in your urls.py with:
from django.conf import settings
from django.urls import path
# or for Django 1.x do
# from django.urls import url
from myapp import views
urlpatterns = [
# original content here
]
if settings.DEBUG:
urlpatterns += [
path('test_500/', views.my_test_500_view, name="test_500"),
# or for Django 1.x do
# url(r'^test_500/$', views.my_test_500_view, name="test_500"),
]
If it's not directly related to any Wagtail pages, then a utils Django app can work well for generic shared code.
Just add url with TemplateView to your urls.py:
from django.views.generic import TemplateView
urlpatterns = [
url(r"^admin/", include(wagtailadmin_urls)),
url(r"^documents/", include(wagtaildocs_urls)),
url(r"^500/", TemplateView.as_view(template_name='500.html')),
]

TypeError: 'function' object has no attribute 'getitem' django url part

hi I started to learn django newly. I want to upload a photo to my website. I did the other parts but in urls part I got error like this. What should I do?
from django.contrib import admin
from django.conf.urls import patterns, include, url
from django.conf import settings
from django.conf.urls.static import static
from bildirge.views import contact, home
from bildirge.urls import *
from django.conf.urls.static import static
from django.conf import settings
from django.contrib import admin
admin.autodiscover()
from bildirge.views import ProfileImageView, ProfileDetailView, ProfileImageIndexView
urlpatterns = patterns[
url(r'^contact/', contact),
url(r'^home/', home),
url(r'^$', ProfileImageIndexView.as_view(), name='home'),
url(r'^upload/', ProfileImageView.as_view(), name='profile_image_upload'),
url(
r'^uploaded/(?P<pk>\d+)/$', ProfileDetailView.as_view(),
name='profile_image'),
url(r'^admin/', include(admin.site.urls))
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
And error is
TypeError: 'function' object has no attribute 'getitem'
thanks in advance
You've got a stray patterns before the opening of the list of URLs. Remove that.

Reach main urls.py and use another app url

I have use 2 apps in my project named post and gallery. In url localhost:8000/en, I am using post.urls specifically "homepage". In homepage, when I want go to {% url "gallery:gallery_detail" "photos" %} it gives me an error. Because even though it takes a keyword "photos" it can not find any pattern specifically "gallery_detail".
My question is how can I reach this anathor app's url ?
My main urls.py:
from django.conf.urls import url,include
from django.conf import settings
from django.conf.urls.static import static
from django.conf.urls.i18n import i18n_patterns
from django.contrib import admin
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^ckeditor/', include("ckeditor_uploader.urls")),
]
urlpatterns += i18n_patterns(
url(r'^gallery/', include("gallery.urls",namespace="gallery")),
url(r'^', include("post.urls", namespace="post")),
)
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
My post.urls:
from django.conf.urls import url
from post.views import HomePageDetailView, AboutDetailView, \
CategoryDetailView, SponsorshipDetailView, CommonDetailView, NewsEntryDetailView
urlpatterns = [
url(r'^$', HomePageDetailView.as_view(), name="homepage"),
url(r'^about/(?P<slug>[-_\w]+)/$', AboutDetailView.as_view(),
name="about_detail"),
url(r'^category/(?P<slug>[-_\w]+)/$', CategoryDetailView.as_view(),
name="category_detail"),
url(r'^sponsorship/(?P<slug>[-_\w]+)/$', SponsorshipDetailView.as_view(),
name="sponsorship_detail"),
url(r'^news/(?P<slug>[-_\w]+)/$', NewsEntryDetailView.as_view(),
name="news_detail"),
url(r'^(?P<slug>[-_\w]+)/$', CommonDetailView.as_view(),
name="common_detail"),
]
My gallery.urls:
from django.conf.urls import url
from gallery.views import GalleryDetailView
urlpatterns = [
url(r'^(?P<slug>[-_\w]+)/$', GalleryDetailView.as_view(),
name="galery_detail"),
]

Django NoReverseMatch url

I can't figure out why I'm returning the following error:
NoReverseMatch at /
Reverse for '' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
Here is the link in my template:
<li>Home</li>
Here are my main urls:
from django.conf.urls import patterns, include, url
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
(r'^', include('merged.catalog.urls')),
(r'^cart/', include('merged.cart.urls')),
(r'^checkout/', include('merged.checkout.urls')),
url(r'^admin/', include(admin.site.urls)),
)
Here is the sub urls:
from django.conf.urls import patterns, url, include
urlpatterns = patterns('merged.catalog.views',
(r'^$','index', {'template_name': 'catalog/index.html'}, 'catalog_home'),
)
It seems like everything is in order, but maybe I'm missing something obvious.
Some changes that might help.
In your template:
<li>Home</li>
In your urls.py
from django.conf.urls import patterns, url, include
urlpatterns = patterns('merged.catalog.views',
(r'^$','index', {'template_name': 'catalog/index.html'}, name='catalog_home'),
)

what's wrong with my urls.py in this example?

I just installed userena, and had the example working from the tutorial, but as soon as I added in a single line in URLS.py, I'm getting an error. In the example below, I added the line mapping the home function from views.py
Now the issue I'm having is that when I go to 127.0.0.1/8000, I get TypeError: string is not callable, but then oddly, if I go to accounts/signup or accounts/signin, I am getting the template that should be appearing if i go to 127.0.0.1/8000.
from django.conf import settings
from django.conf.urls import patterns, include, url
from django.conf.urls.static import static
from django.views.generic import TemplateView
from accounts import views
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r"^$", 'home'),
url(r'^admin/', include(admin.site.urls)),
(r'^accounts/', include('userena.urls')),
)
Here is my accounts/views.py
from django.shortcuts import render
from django.http import HttpResponseRedirect
def home(request):
return render('homepage.html')
You need to remove the quotes in the url and import that view
from accounts.views import home
urlpatterns = patterns('',
url(r"^$", home),
url(r'^admin/', include(admin.site.urls)),
(r'^accounts/', include('userena.urls')),
)
You can steel use the strings in the url() but you must use the format 'app.views.viewname'
urlpatterns = patterns('',
url(r"^$", 'accounts.views.home'),
url(r'^admin/', include(admin.site.urls)),
(r'^accounts/', include('userena.urls')),
)
Or name the module in the first argument as string to patterns()
urlpatterns = patterns('accounts.views',
url(r"^$", 'home'),
url(r'^admin/', include(admin.site.urls)),
(r'^accounts/', include('userena.urls')),
)
the issue was I forgot to include the request in the return render.
The correct answer is that render is being called incorrectly. Actually, the views.py file would raise a SyntaxError, but we'll let that slide :)
# views.py
from django.shortcuts import render
def home(request):
return render(request, 'homepage.html')