I’m making my first django based backend server and I registered the urls for each app like
urlpatterns = [
path('admin/', admin.site.urls),
path('backfo/', include('backfo.urls')),
path('commun/', include('commun.urls')),
path('starts/', include('starts.urls')),
path('travleres/', include('travleres.urls')),
path('starts/', include('starts.urls')),
path('new/', include('new.urls')),
path('joint/', include('joint.urls')),
]
Then I get this error in cmd saying ->
ModuleNotFoundError: No module named 'backfo.urls'
I don’t get what went wrong and if you need more code I’ll post it on.
In settings.py add module in INSTALLED_APPS
Related
My code is not working, and I am not sure why.
I have the problem with hours_ahead function.
Here is urlpatterns path('time/plus/(\d{1,2})/', hours_ahead),
And I imported hours_ahead too
One of these may work
In your urls.py add something like:
urlpatterns = [
path('admin/', admin.site.urls),
path('hours/<int:offset>/', hours_ahead)
]
the "int:offset" is a way of saying what is the parameter you are going to receive and the type.
in settings.py add:
INSTALLED_APPS = [ # careful to not create another INSTALLED_APPS,add the app to the list!
# ...
'playground'
]
Also, I got this error on my terminal:
CommandError: 'playgrounds' conflicts with the name of an existing Python module and cannot be used as an app name. Please try another name.
I could not run the code until I created and app with another name.
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!
I am trying Django for an upcoming project and going through a tutorial and running into issue with defining URL paths. Below is the project structure showing the urls.py at the project root.
The urls.py in my timer package is pretty simple:
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name='index'),
]
However when I launch the application and navigate to localhost:8080/timer/ I am getting a 404. Any suggestions what I should be looking at?
You can try to change URLs in the settings of the whole project like this:
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^timer/$', include('timer.urls')),
]
As for the timer, the URLs will be like this:
urlpatterns = [
url(r'^$', views.index, name="index"),
]
Don't forget about r's in the url().
It turns out that I created the urls.py under a wrong folder. I misunderstood the instructions and created the urls.py in the same folder as manage.py. Once I add the new url pattern in the file projectdb/projectgb/urls.py, the issue is fixed. Thanks.
when I try to run the Django server I'm treated with this error:
ImportError "No module named router"
I have no problems with the imports, I'm sure as this problem is only when I try to work with routers, for example; viewsets in my views.py work perfectly, this means that viewsets are successfully imported and restframework is installed. Thanks!
from django.conf.urls import url, include
from django.contrib import admin
from rest_framework.routers import SimpleRouter
router = SimpleRouter()
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')),
url(r'^api/v2/', include('router.urls')),
]
django rest framework official documentation says this about importing module. Read more here: http://www.django-rest-framework.org/
from rest_framework import routers
router = routers.SimpleRouter()
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')),
url(r'^api/v2/', include(router.urls)),
]
Since you are using 'router.urls' as string. Django is probably going and looking for a module named router which it fails to find. Because we have not imported router module. We have imported SimpleRouter class.
router is an object that you have created using router = SimpleRouter()
I hope you understood your mistake. Read more on importing routers and using them here: http://www.django-rest-framework.org/api-guide/routers/
I'm following the Django Tutorials, I'm at the end of part 3, at Decoupling the URLconfs, at http://docs.djangoproject.com/en/1.1/intro/tutorial03/#intro-tutorial03 and I'm getting a "No module named urls" error message.
When I change:
from django.conf.urls.defaults import *
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('mysite.polls.views',
(r'^polls/$', 'index'),
(r'^polls/(?P<poll_id>\d+)/$', 'detail'),
(r'^polls/(?P<poll_id>\d+)/results/$', 'results'),
(r'^polls/(?P<poll_id>\d+)/vote/$', 'vote'),
(r'^admin/', include(admin.site.urls)),
)
to:
from django.conf.urls.defaults import *
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
(r'^polls/', include('mysite.polls.urls')),
(r'^admin/', include(admin.site.urls)),
)
I changed include('mysite.polls.urls')), to include(mysite.polls.urls)),, but it still didn't work.
How to solve this problem?
UPDATE 2: at mysite/polls/urls.py is
from django.conf.urls.defaults import *
urlpatterns = patterns('mysite.polls.views',
(r'^$', 'index'),
(r'^(?P<poll_id>\d+)/$', 'detail'),
(r'^(?P<poll_id>\d+)/results/$', 'results'),
(r'^(?P<poll_id>\d+)/vote/$', 'vote'),
)
UPDATE 4: the whole project is at
http://www.mediafire.com/?t1jvomjgjz1
I had a similar problem in my project root ... django complained that it couldn't find the module mysite.urls.
Turns out my ROOT_URLCONF variable in settings.py, which was set up using the default values, was set incorrect. Instead of "mysite.urls", it should have been simply "urls"
I changed it, and voila, it worked.
I can't re-produce the import error on my machine using your project files (Windows 7, Django 1.1.1, Python 2.6.4). Everything imported fine but the urls were not specified properly (like the tutorial shows). Fixing the code:
/mysite/urls.py:
from django.conf.urls.defaults import *
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
(r'^polls/', include('mysite.polls.urls')),
(r'^admin/', include(admin.site.urls)),
)
/mysite/polls/urls.py:
from django.conf.urls.defaults import *
urlpatterns = patterns('mysite.polls.views',
(r'^$', 'index'),
(r'^(?P<poll_id>\d+)/$', 'detail'),
(r'^(?P<poll_id>\d+)/results/$', 'results'),
(r'^(?P<poll_id>\d+)/vote/$', 'vote'),
)
Visit http://127.0.0.1:8000/polls/ - I received a TemplateDoesNotExist exception because the template file is missing.
I'm afraid my answer might be to reboot and try it again. ;)
Is there an __init__.py inside mysite/polls/ directory?
I also had a weird problem with "No module named mysite.urls".
The admin site was down and the my whole site.
The solution, after a few hours of searching the web, was on my side : Django is caching some of the settings in a file that he knows from an environment variable.
I just closed my terminal in which i was doing the runnserver thing and opened a new one.
I did exactly the same thing. Python newbie mistake by reading ahead. I created a file call "polls.url" thinking it was some sort of special django template file.
I misunderstood the text:
"Now that we've decoupled that, we need to decouple the polls.urls URLconf by removing the leading "polls/" from each line, and removing the lines registering the admin site. Your polls.urls file should now look like this:
"
It should really read:
"Now that we've decoupled that, we need to decouple the polls.urls URLconf by removing the leading "polls/" from each line, and removing the lines registering the admin site. Your polls/urls.py file should now look like this:
"
Late to the party but I fixed my problem by correcting a typo inside settings.py INSTALLED_APPS. I had 'webbapp' instead of 'webapp' so you might want to check on that as well (for people still having the problem)
Like Ryan Bagwell, problem was (at least temporarily) solved by changing ROOT_URLCONF in myproject/myproject/settings.py.
I had to add "myproject" to ROOT_URLCONF to have there this:
"%s.myproject.urls" % PROJECT_APP