Routing error using Wagtail v2 with Django v1.11 - python

Can't seem to find anything on this so far, I'm guessing I have something misconfigured somewhere.
I have a pre-existing Django app and am trying to use Wagtail to add a blog in. I have installed as per the instructions and I can access the default landing page so it seems to be installed however I'm stuck with the below error when attempting to access the admin for it and am not sure how to proceed. Guessing its something to do with not defining namespaces somewhere, the Wagtail docs say that its compatible with Django v1.11 but their integration documentation is for Django v2 specifically and is using re_path etc.
'wagtailadmin_api_v1' is not a registered namespace
My main project urls.py
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^blog/', include('blog.urls', namespace='blog')),
url(r'^taggit_autosuggest/', include('taggit_autosuggest.urls')),
url(r'^autocomplete/', include(ac_urls, namespace='ac')),
url(r'^', include('website.urls', namespace='website')),
]
My blog app's urls.py (which is fresh from a "python manage.py startapp blog")
from django.conf.urls import url, include
from wagtail.admin import urls as wagtailadmin_urls
from wagtail.documents import urls as wagtaildocs_urls
from wagtail.core import urls as wagtail_urls
app_name = 'blog'
urlpatterns = [
url(r'^cms/', include(wagtailadmin_urls)),
url(r'^documents/', include(wagtaildocs_urls)),
url(r'', include(wagtail_urls)),
]
When I attempt to access localhost:8000/blog/ I get the default wagtail landing page, if I go to localhost:8000/blog/cms/ I get the above error though. If I go to localhost:8000/blog/documents/ I get a 404 as well.
Not sure where I'm going wrong, have tried using a version of wagtail that still used the Django v1.11 way of routing in urls.py but I got the same error!

Related

Django app returning 404 error even if urls seem to be correct according to tutorials

I am starting my first django application. I constantly keep getting 404 error after turning on server locally in my computer. I don't see any reason for such return because urls seem to be correct when compared to tutorials and guides on the internet.
This is my urls file inside app (app name is reservations)
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name='index')
]
This is urls file in project folder (project name is website)
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('admin/', admin.site.urls),
path('reservations/', include('reservations.urls'))
]
and this is index function which is supposed to show basic html
def index(request):
response = """<html><body><p>This is home page</p></body></html>"""
return HttpResponse(response)
I thought that my urls are written incorrectly so i tried writing them in different way but it never worked. Thanks for any help.

How do I add urls from a Django app module into my main urls.py?

Hi So I'm learning a course but it's a bit date on Django 1 and I'm using Django 3. (I'm a newbie so didn't realize the difference)
In one section, it says in my accounts app to make a new module for passwords. Then to create an init.py file and an urls.py.
I've done this and I"ve created very standard Urls for password reset and change. And have also included the new templates in my project root directory templates folder under registration.
This is my urls. py in my accounts/passwords folder
from django.urls import path
from django.contrib.auth import views as auth_views
app_name='accounts.passwords'
urlpatterns = [
path('password/change/',
auth_views.PasswordChangeView.as_view(),
name='password_change'),
path('password/change/done/',
auth_views.PasswordChangeDoneView.as_view(),
name='password_change_done'),
path('password/reset/',
auth_views.PasswordResetView.as_view(),
name='password_reset'),
path('password/reset/done/',
auth_views.PasswordResetDoneView.as_view(),
name='password_reset_done'),
path('password/reset/<uidb64>/<token>/',
auth_views.PasswordResetConfirmView.as_view(),
name='password_reset_confirm'),
path('password/reset/complete/',
auth_views.PasswordResetCompleteView.as_view(),
name='password_reset_complete'),
]
In my main urls.py I've added
path('accounts/', include("accounts.passwords.urls")),
When I try it out it says there is no reverse match for the name, etc Password_reset_done.
When I put the urls/paths directly into my main urls.py it works.
So I wanted to check, how do I include the urls from a module in an app?
I gave the app_name as "accounts.passwords" and also added that as an app in the settings on my main. Just thought I'd try.
I've tried to google this but couldn't find an answer
Thanks

Getting error when I am trying to fetch my main url patterns

I am a beginner in Django I have created a Django project in that I have included two more application when I did add urls.py file in both Applications both are working well but when I am fetching my main admin URL it is giving an error
Page not found (404)
Request Method: GET
URL: http://127.0.0.1:8000/
the URLconf defined in mac.urls, Django tried these URL patterns, in this order:
admin/
shop/
blog/
The empty path didn't match any of these.
You're seeing this error because you have DEBUG = True in your Django settings file. Change that to
False, and Django will display a standard 404 page.
when I am fetching this URL in http://127.0.0.1:8000/ i am getting an error it is working for http://127.0.0.1:8000/shop/
here is my main urls.py
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('shop/', include('shop.urls')),
path('blog/', include('blog.urls')),
]
Your django app has 3 routes:
http://127.0.0.1:8000/admin/ goes to django admin app
http://127.0.0.1:8000/shop/ goes to your shop app
http://127.0.0.1:8000/blog/ goes to your blog app
And since you have no configuration for http://127.0.0.1:8000, you see an error instead.
You can see that in the error, when django tries to match your url with list of available urls.
If you want to get admin app on url http://127.0.0.1:8000, change urls.py to:
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('', admin.site.urls),
path('shop/', include('shop.urls')),
path('blog/', include('blog.urls')),
]
It's generally not advisable to set admin app at root url - it has it's own system of urls inside (admin/<app_name>/<model_name>), so chances are it will shadow your urls and make the unreachable.
Create a view that will be your front page.
From there you should link to the other areas of your website.
Don't direct that to admin, that's ridiculous.
You've created a Django project and started two apps. You should have a project-level urls.py file and then an app-level urls.py file for each of your apps.
To explain that in greater detail lets say our Django project is called config and our two apps are called app1 and app2. Your project-level urls.py file, which will be located at config/urls.py, could contain the following:
# config/urls.py
from django.contrib import admin
from django.urls import path, include
from django.views.generic.base import TemplateView
urlpatterns = [
path('admin/', admin.site.urls),
path('', TemplateView.as_view(template_name='home.html'),
name='home'),
path('app1/', include('app1.urls')),
path('app2/', include('app2.urls')),
]
In this file we specify a route for our admin panel, which on your local server will be located at http://127.0.0.1:8000/admin. We've also specified a home route, the second path with the empty string. This means when you navigate to http://127.0.0.1:8000/ you will be directed to your home page (for the example above I just used a generic built-in view). It's not a good idea to route immediately to your admin panel.
We've also included paths to our other two apps. What these two lines essentially say is: "include the urls from this other app". Now we need to create two urls.py files, one for each of our apps. In this example I'll just focus on the urls.py file for app1:
# app1/urls.py
from django.urls import path
from .views import AppContentView
urlpatterns = [
path('content/', AppContentView.as_view(),
name='app_content'),
]
This is a view that you would have to create, but what we've now done is we've created one path that will be located at http://127.0.0.1:8000/app1/content. In fact any new paths we create in this file will always begin with http://127.0.0.1:8000/app1/, because we've already told Django in our project-level urls.py to include the urls from the app1 urls.py file so we've essentially prefixed all of these paths with /app1/.
If you think of urls configurations like a tree it might help too:
Project Level Url Configs.
|
|
|
___________________________
| |
| |
App 1 Url Configs. App 2 Url Configs.

Django backend not returning JSON on production server, getting 404

I have a Django backend that returns json data. I'm able to get data back on my localhost but got a 404 on production server. I'm running nginx in front of gunicorn server. Any ideas why I'm getting a 404? Shouldn't this be able to work to retrieve json data, or do I need to use django rest framework and implement viewsets to make this work?
Not Found
The requested URL /about was not found on this server.
urls.py
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^about', about.get_info),
]
about.py
from django.http import JsonResponse
def get_info(req):
return JsonResponse({"test": "hello"})
The problem is inside url.py. The way the rules are defined currently, it would only allow you to open about/ and admin/, i.e. with the / at the end. To fix this, you can define the URLs as following:
urlpatterns = [
url(r'^admin/$', admin.site.urls),
url(r'^about/$', about.get_info),
]
Now you should be able to use both admin/ and admin to access the page.

Django login system

I'm looking for a "ready" example of a Login/Register/Authentication system for my site written in Python (so with Django I suppose).
EDIT:
I've tried the Django-registration, see this tutorial
In the tutorials (see STEP 4), I need to update the file urls.py to:
from django.conf.urls.defaults import *
from django.views.generic.simple import direct_to_template
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
(r'^admin/(.*)', admin.site.root),
(r'^accounts/', include('registration.urls')),
(r'^$', direct_to_template,
{ 'template': 'index.html' }, 'index'),
)
But when I do this, the Admin page is not available.
When I chance
(r'^admin/(.*)', admin.site.urls)
instead of
(r'^admin/(.*)', admin.site.root)
When I do this, I could login to the Admin page, but I couldn't click on anything...
What am I doing wrong?
https://github.com/ubernostrum/django-registration
This is a user-registration application for Django. There are two registration workflows (one-step, and two-step with activation) built in, and it's designed to be extensible and support building additional workflows.
Try django-registration or Pinax.

Categories

Resources