django 'admin' is not a registered namespace in pybbm-forum app on subdomain - django

I have django 1.10.7, python2.7, installed django-hosts, pybbm app.
Pybbm forum on subdomain forum.example.com.
When i'l trying open topic on url forum.example.com/topic/1/, that already have created, i get error.
NoReverseMatch at /topic/1/
u'admin' is not a registered namespace
my hosts.py
# -*- coding: utf-8 -*-
from django_hosts import patterns, host
from django.conf import settings
host_patterns = patterns('',
host(r'example.com', settings.ROOT_URLCONF, name='www'),
host(r'forum', 'forums.urls', name='forum'),
)
my forums/urls.py, where i included pybb urls
from django.conf.urls import include, url
from django.conf.urls.static import static
from django.conf import settings
urlpatterns = [
url(r'^', include('pybb.urls', namespace='pybb')),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Can you help how to better configure pybbm forum app with my django project on subdomain?

Looks like you have no admin url in your 'forums/urls.py' and the template that renders '/topic/1/' has some django url link pointing to admin routes (e.g. Foo) that doesn't even exist. Can you show the template code?

Related

Django-filer problem when retrieve uploaded image in Django admin interface or any http|s request [duplicate]

I am using Django-Filer in my admin on a Django web project which is hosted in PythonAnywhere. I have gone through the installation instructions but I am having trouble accessing the canonical urls the Filer makes for each file. It seems I am being directed to an extended url that Filer.urls is not recognizing (the non-canonical part starts at /filer-public/; this is a directory that is being created and storing my files on the separate PythonAnywhere file directory).
Is there an error in my urls syntax? An error in my views.canonical? I am unsure of why plugging in the exact canonical url redirects me to this extended version of the url.
Python: 3.7
Django: 2.2
Canonical URL:
/filer/sharing/1560887480/39/
ERROR / DEBUGGING SCREEN
Page not found (404)
Request Method: GET
Request URL: http://www.mywebsite.com/filer/sharing/1560887480/39/filer_public/36/ea/36ea58a8-f59c-41ad-9d1f-00a976603eb1/big1.jpg
Using the URLconf defined in mywebsitesite.urls, Django tried these URL patterns, in this order:
admin/
^filer/ sharing/(?P<uploaded_at>[0-9]+)/(?P<file_id>[0-9]+)/$ [name='canonical']
The current path, filer/sharing/1560887480/39/filer_public/36/ea/36ea58a8-f59c-41ad-9d1f-00a976603eb1/big1.jpg, didn't match any of these.
APP URLS: /mywebsite/.virtualenvs/env/lib/python3.7/site-packages/filer/urls.py
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from django.conf.urls import url
from . import settings as filer_settings
from . import views
urlpatterns = [
url(
filer_settings.FILER_CANONICAL_URL + r'(?P<uploaded_at>[0-9]+)/(?P<file_id>[0-9]+)/$', # flake8: noqa
views.canonical,
name='canonical'
),
]
APP VIEWS: /mywebsite/.virtualenvs/env/lib/python3.7/site-packages/filer/VIEWS.py
# -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals
from django.http import Http404
from django.shortcuts import get_object_or_404, redirect
from .models import File
def canonical(request, uploaded_at, file_id):
"""
Redirect to the current url of a public file
"""
filer_file = get_object_or_404(File, pk=file_id, is_public=True)
if (not filer_file.file or int(uploaded_at) != filer_file.canonical_time):
raise Http404('No %s matches the given query.' % File._meta.object_name)
return redirect(filer_file.url)
BASE URLS: /home/mywebsite/mywebsite/urls.py
from django.contrib import admin
from django.urls import include, path
from django.conf.urls import url
from django.views.generic import TemplateView
from quotes.views import Register
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('django.contrib.auth.urls')),
path('', include('pages.urls')),
url(r'^filer/', include('filer.urls')),
]
BASE SETTINGS: /home/mywebsite/mywebsite/settings.py
FILER_CANONICAL_URL = 'sharing/'
I was able to get the canonical url to work by configuring the static and media root in my urls and settings files, as shown below.
urls.py
from django.conf import settings
from django.conf.urls.static import static
from django.contrib import admin
from django.urls import include, path
from django.conf.urls import url
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('django.contrib.auth.urls')),
url(r'^filer/', include('filer.urls')),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
settings.py
MEDIA_ROOT = os.environ.get('FILER_MEDIA_ROOT', os.path.join(BASE_DIR, 'media'))
MEDIA_URL = '/home/mywebsite/media/'
I was able to solve this by not including the filer.urls but rather specifying the url pattern directly in my projects urls.py file.
Django 3.1.7
django-filer 2.1.2
/myproject/myproject/urls.py:
...
from filer import views as filer_views
from .settings import FILER_CANONICAL_URL
...
urlpatterns = [
url(r'^filer/'+FILER_CANONICAL_URL+r'/(?P<uploaded_at>[0-9]+)/(?P<file_id>[0-9]+)/$',
filer_views.canonical,
name='canonical'),
...,
]
/myproject/myproject/settings.py
...
FILER_CANONICAL_URL = 'somefolder/'
However I'm still not sure where the extra space was coming from in the first place - the filer urls.py and settings.py look fine as far as I can tell.

Django/Wagtail Media Files not showing up in the admin portal on a fresh install

I am working on a site in dev that contains a media folder. When I do a fresh setup of the site (empty db) and do all the migrations and steps to get the site up and running I noticed in the admin portal none of the images and assets in the media folder dont show up even though they exist. I have to re-import an image and then it shows up in the admin portal as expected. I have looked all over and cannot find an answer. To put it simply why isnt the admin portal importing existing files in the media folder on a fresh setup?
django==3.2
wagtail==3.0
base.py
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = 'media/'
urls.py
from django.conf import settings
from django.conf.urls import include, url
from django.contrib import admin
from wagtail.admin import urls as wagtailadmin_urls
from wagtail.core import urls as wagtail_urls
from wagtail.documents import urls as wagtaildocs_urls
from wagtail.contrib.sitemaps.views import sitemap
from search import views as search_views
urlpatterns = [
...
]
if settings.DEBUG:
from django.conf.urls.static import static
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
# Serve static and media files from development server
urlpatterns += staticfiles_urlpatterns()
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
If anyone has any idea?
That is totally normal. Just as you need to import your page data into the database, you also need to import the information about your documents into the database (in addition to having the files). You can write a script to help with these imports. I don't have one for images but here is one I wrote for importing documents from a nested directory in the file system into a nested set of collections: https://gist.github.com/cnk/54031ca6775fa0d29997449a1e2010ec

Improperly Configured urls.py during Django deployment (Django 2.1)

This is my first time deploying Django. My app runs fine locally, but when I deploy, I get this error:
ImproperlyConfigured at /admin/
The included URLconf module 'search.urls' from '/home/imeaytbc/myproject/search/urls.py' does not
appear to have any patterns in it. If you see valid patterns in the
file then the issue is probably caused by a circular import.
My urls.py file is exactly the same as the one run on my computer:
from django.urls import path
from . import views
app_name = 'search'
urlpatterns = [
path('', views.query_search, name='query_search'),
path('article/<int:ArticleID>/', views.article_detail, name='article_detail')
]
Is there anything I need to change in regards to deployment? All the changes I made to my files regarding deployment are about static and media file directories. What else do I need to change for deployment? As far as I am aware, I have uploaded all files to the hosting server and the app shouldn't be missing any file.
EDIT: added main urls.py
from django.contrib import admin
from django.urls import include, path
from django.conf import settings
from django.conf.urls.static import static
from django.views.generic import RedirectView
urlpatterns = [
path('admin/', admin.site.urls),
path('search/', include('search.urls')),]

Why does this URL work in Django? It is not in urls.py

I've never worked with Django before. I'm taking over a Django project that was started by another programmer, who is now long gone. There is some magic happening in the code that I do not understand. For instance, in this file:
urls.py
I see this:
from django.conf.urls import url, include
from django.contrib import admin
from django.core.urlresolvers import reverse_lazy
from django.views.generic.base import RedirectView
from django.conf import settings
from core import views as core_views
from sugarlab.search.views import validate_collections, create_document, delete_interest, rename_interest, add_url, my_interests
from sugarlab.search.views import content, score, terms
from django.contrib.auth.views import logout as django_logout
from django.conf.urls.static import static
admin.autodiscover()
urlpatterns = [
url(r'^admin/logout/$', django_logout,
{'next_page': '/'}),
url(r'^admin/', admin.site.urls),
url(r'^accounts/logout/$', django_logout,
{'next_page': '/'}),
url(r'^accounts/', include('allauth.urls')),
url(r'^unsecured/$', core_views.home),
The confusing part is these two lines:
from django.conf import settings
url(r'^accounts/', include('allauth.urls')),
"allauths" is some configuration set inside of this file:
settings/common.py
The data looks like this:
'allauth',
'allauth.account',
'allauth.socialaccount',
'django.contrib.auth',
'django.contrib.sites',
# Social/3rd party Authentication apps
'allauth.socialaccount.providers.linkedin_oauth2',
'captcha'
Somehow this is a URL that actually works:
/accounts/signup/
This file is completely blank:
settings/__init__.py
So I've two questions:
how does "import settings" manage to magically import allauths?
how does /accounts/signup/ map to an actual view? I don't see anything in urls.py, nor in settings, that would make me think that /accounts/signup/ is a valid url.
how does /accounts/signup/ map to an actual view? I don't see anything in urls.py, nor in settings, that would make me think that /accounts/signup/ is a valid url.
url(r'^accounts/', include('allauth.urls')),
there is another urls file inside the app called allauth if it's installed by "pip" you can find it in the following directory "lib/python*/site-package/allauth"
= the python version you are using for example 2.7 or 3.5
ps allauth is a well known 3rd party app you can quick google search django allauth and you'll find it
how does "import settings" manage to magically import allauths?
it doesnt import settings is used for something else for example setting static file url like that
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

Rewrite URL to exclude Django application name

on my live server, I am trying to remove/rewrite the need to include the application name in the URL, as without it I get a 404. For example:
http://www.example.com/myapp/page.html
to
http://www.example.com/page.html
This is especially tricky since i don't want this to affect the django admin URL which excludes the app name.
This is on Apache Server on Ubuntu on a shared host (A2).
You're root urls.py most likely looks something like this:
"""
Definition of urls for api.
"""
from django.conf import settings
from django.conf.urls import include, url
from django.conf.urls.static import static
from django.contrib import admin
urlpatterns = [
# Uncomment the admin/doc line below to enable admin documentation:
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
url(r'^admin/', admin.site.urls),
url(r'^myapp/', include('myapp.urls'))
]
When you just replace r'^myapp/' with r'^' the app will be automatically tried, when there is nothing else before that fits (so it's best to put it to the end of the list)