ModuleNotFoundError: No module named 'myapp.url' - django

I was creating my django first app. I added this code
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('myapp.url'))
]
from my project urls.py file to get my html code from my app url.py, but i keep getting this error when i want to run my server.
ModuleNotFoundError: No module named 'myapp.url'

Related

Django: UserAuthentication | ModuleNotFoundError: No module named 'userAuthentication'

I've been trying to create a user login and logout with django's bulid-in authenticated views.
I changed the project-level URL pattern
urlpatterns = [
path('admin/', admin.site.urls),
path('accounts/',include('django.contrib.auth.urls')),
path('', include('home.urls')),
]
added template registration/login.html
and updated LOGIN_REDIRECT_URL in settings.py
but still getting ModuleNotFoundError: No module named 'userAuthentication'.I don't know if I am missing anything in these it would be appreciated if anyone can give the heads up.
note: I was trying to recreate exactly this
https://docs.djangoproject.com/en/4.0/topics/auth/default/#module-django.contrib.auth.views
Installed Apps and middleware in settings.py

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),
]

when i startapp "article", and python manage.py runserver, and I do not know why "module 'article.admin' has no attribute 'site" this error happen?

I start up an app named "article" but and configure an import like this: from article import * in the setting configure file, then when I run python manage.py runserver the error ocuur like this AttributeError: module 'article.admin' has no attribute 'site', when I comments from article import * with #, it will work on well, I do not know how from article import * raise the problem.
from article import *
atterns = [
path('admin/', admin.site.urls),
url(r'^article/',include('article.urls',namespace='article')),
]
The output:
File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
File "D:\pythonTestfolder\xuegod\blogtest\blogtest\urls.py", line 25, in <module>
path('admin/', admin.site.urls),
AttributeError: module 'article.admin' has no attribute 'site'
You don't need to import from your article app here
especially all of its contents with *
include method will work with a string of app_name and it's urls.py file , as you have wright corectly
and after that if it is a newer version of django project you are using , try not to use
url method because it is going to be deprecated use re_path() instead , if you want to check for regex urls:
from django.urls import path, re_path, include
urlpatterns = [
path('admin/', admin.site.urls),
re_path(r'^article/',include('article.urls',namespace='article')),
]

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')),
]

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

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.