File Browser no grapelli: NameError: name 'site' is not defined - django

I'm following this tutorial for install django-tinymce4-lite. At the end of the tutorial there are the indications to install django-filebrowser-no-grappelli.
I use Django 2.1.1 but even though I've followed all the indications, after the installation of the file browser was shown this message:
File
"/var/www/html/dev/miosito/django/beautifulsite_v0.1.1/djangosite/djangosite/urls.py",
line 25, in
path('admin/filebrowser/', include(site.urls)), NameError: name 'site' is not defined
Here there is urls.py:
from django.contrib import admin
from django.urls import path, include
from django.conf import settings
from django.conf.urls.static import static
from filebrowser.sites import site #sorry I've forgot this
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('testapp.urls')), #app for my tests
path('tinymce/', include('tinymce.urls')),
path('admin/filebrowser/', include('site.urls')),
]
if settings.DEBUG:
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
What I've wrong?
EDIT after Yeo correction:
I've add the string that I've forgot and I've correct
path('admin/filebrowser/', include(site.urls)),
with
path('admin/filebrowser/', include('site.urls')),
but now I've this new error:
ModuleNotFoundError: No module named 'site.urls'; 'site' is not a
package

Try the following: (remove the include)
# ...
from filebrowser.sites import site
# ...
urlpatterns = [
# ...
path('admin/filebrowser/', site.urls),
# ...
]
Always refer to the package official documentation, when you encounter errors specific to the package itself. (In this case is django-filebrowser, although the main repo seems to be at django-filebrowser-no-grappelli). Blog sometime gets outdated easily. For example the guide from your link does not specify what Django version they are using. (Looking from the way the tutorial was written include, it seems to be Django<1.9 (reference)).
If you're using Django>=2, then the official document should explain the correct way to install this package.

Related

Base "/" not found in Django

My django project ornaments has only one app called balls. I would like the server to point to its index when I do manage.py runserver but I get this error:
Here's my 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
urlpatterns = [
path('balls/', include('balls.urls')),
path('admin/', admin.site.urls),
]
urlpatterns += [
path('', RedirectView.as_view(url='balls/', permanent=True)),
]
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
I am also including the project structure. Please note that the string ball appears nowhere in my code (as per a search).
According to your screenshot, you're sending requets to http://127.0.0.1:8000/ball and this URL not found on given path path('balls/', include('balls.urls')) so try to go to this http://127.0.0.1:8000/balls

Django ModuleNotFoundError: No module named 'product'

I am absolute new to django and I have followed the example of Django documentation https://docs.djangoproject.com/en/3.0/intro/tutorial01/
but getting a problem in main project's urls.py file which is Module not found error pls help. Heres my main projects urls.py:
`from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('polls/', include('product.urls')),
path('admin/', admin.site.urls),
]

How to fix the error for django 'django.core.exceptions.ImproperlyConfigured' with urls?

from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('polls/', include('polls.urls')),
]
There is an error when i add url to url.py.
when i run the code in terminal : 'python manage.py runserver' ; then the follwing error is displayed in the terminal -
django.core.exceptions.ImproperlyConfigured: The included URLconf
'<module 'polls.urls' from
'C:\\Users\\Administrator\\PycharmProjects\\website2\\mysite\\polls\\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.
I searched everywhere for the solution but i couldn't find it. Please help me to get out of it.
I think this error most of u misunderstand, circular error imports are very rare in django only in flask it is frequent .
This error is caused by mispelling 'urlpatterns' in the urls.py which has been created in a django app.
Also it can be caused by not defining it in your urlpatterns in the urls.py file
Probably the error is caused by one of the above.
Its that easy
make sure in your polls app, you have a file called urls.py, which should look something like this:
from django.urls import path
from . import views
urlpatterns = [
path('', views.your_view),
]
If you haven't configured the views.py page in your polls app, then you can leave urlpatterns blank for now and you shouldn't see any errors.
This error might be coming because of the adimn in urls.py
urlpatterns = [
path('admin/', admin.site.urls),
path('polls/', include('polls.urls')),
]
When the polls path was removed by me, the website was running properly. So try comment the polls path in urls
urlpatterns = [
path('admin/', admin.site.urls),
#path('polls/', include('polls.urls')),
]

Django: TypeError using manage.py [answered, syntax error]

I'm running Ubuntu 18.04, python3.7, and django2.1
Currently on just step 2 on Mozilla's django tutorial : https://developer.mozilla.org/en-US/docs/Learn/Server-side/Django/skeleton_website
Checked my code multiple times and it's identical to Mozilla's code.
When I try to run python3.7 manage.py runmigrations or python3.7 manage.py runserver I get:
TypeError: bad operand type for unary +: 'list'
I've quadruple checked to make sure that my code is identical to the guides.
Please comment if it'd be helpful for me to post anymore of my code however.
locallibrary/locallibrary/urls.py
from django.contrib import admin
from django.urls import path
urlpatterns = [
path('admin/', admin.site.urls),
]
from django.views.generic import RedirectView
urlpatterns += [
path('', RedirectView.as_view(url='/catalog/')),
]
from django.conf import settings
from django.conf.urls.static import static
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
Catalog/urls.py
from django.urls import path
from catalog import views
urlpatterns = [
]
Here is my traceback:
https://pastebin.com/2CzdtWzK
Please scroll all the way down to the 'raw paste data'
It was a typo in my urls.py. I used =+ instead of +=. Thanks #ger.s.brett!

FIX ImportError: cannot import name 'patterns'

I am writing documentaton for the API I have already built. I have already installed drfdocs and added it in INSTALLED_APPS then configured the urls yet I get the following logs below. I think the version of rest_framework_docs is importing patterns which I believe its deprecated, new versions of django are no longer using it. How do I fix this?
I have django 1.11 and using python3. I get the following logs when I try to run ther server:
Logs
File "/usr/local/lib/python3.5/dist-packages/rest_framework_docs/urls.py", line 1, in <module>
from django.conf.urls import patterns, include, url
ImportError: cannot import name 'patterns'
Views.py
from django.conf.urls import include, url
from django.contrib import admin
from rest_framework.urlpatterns import format_suffix_patterns
# from organizations.backends import invitation_backend
from rest_framework.authtoken.views import obtain_auth_token
from django.conf.urls.static import static
from django.conf import settings
urlpatterns = [
url(r'api/token/', obtain_auth_token, name='api-token'),
# url(r'^account/', include('accounts.urls', namespace='account')),
url(r'^hr/', include('hr.urls', namespace='hr')),
url(r'^acc/', include('Accounting.urls', namespace='Accounting')),
url(r'^payroll/', include('payroll.urls', namespace='payroll')),
url(r'^bill/', include('bill.urls', namespace='bill')),
url(r'^docs/', include('rest_framework_docs.urls')),
url(r'^proc/', include('procurement.urls', namespace='procurement')),
# url(r'^accounts/', include('organizations.urls')),
# url(r'^authority/', include('authority.urls')),
url(r'^organization/', include('organizations.urls')),
url(r'^admin/', admin.site.urls),
# url(r'^invitations/', include(invitation_backend().get_urls())),
]
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)