I am trying this with Django 1.4 on Windows 7 with the default web server.
The site starts with no errors. but when I browse to localhost:8000
I get the following error
ImportError at /
No module named urls
I see where the error comes from
It is in the main URLs.py file - (r'^admin/', include('django.contrib.admin.urls')),
If I remove that form URLs.py file the home page comes up. I don't see urls.py file in "C:\Python27\Lib\site-packages\django\contrib\admin" folder. So, the error makes sense.
But that line has to be there to get Django-Registration package working. All the blogs I read about has that line. How do I get pass this? Thanks so much for your error.
Fixed the url.py per Siva's instructions below. but no luck.
from django.conf.urls import patterns, include, url
from SOWLAPP.views import *
from CATALOG.views import *
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'SOWL.views.home', name='home'),
# url(r'^SOWL/', include('SOWL.foo.urls')),
# Uncomment the admin/doc line below to enable admin documentation:
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
url (r'^user/(\w+)/$', user_page),
(r'^login/$', 'django.contrib.auth.views.login'),
(r'^catalog/$', home),
(r'^static/(?P<path>.*)$', 'django.views.static.serve',
{ 'document_root' : 'C:/SHIYAM/Personal/SuccessOwl/SOWL0.1/SOWL/SOWL/static'}),
(r'^admin/', include('django.contrib.admin.urls')),
(r'^accounts/', include('registration.urls')),
(r'^$', main_page),
)
Regards,
SHM
Check the ROOT_URLCONF entry in your settings file. The following links might help you.
https://docs.djangoproject.com/en/dev/ref/settings/#root-urlconf
How to set correct value for Django ROOT_URLCONF setting in different branches
But Your urls.py looks messy. 2 entries for same url?
url(r'^admin/', include(admin.site.urls)),
(r'^admin/', include('django.contrib.admin.urls')),
The following entry should comes at the end.
(r'^$', main_page),
Try to comment out each line inside:
urlpatterns = patterns('',
...
)
if it does not solve the error Than (as I've expected) error in the urls.py imports...
I suspect they are somewhere here:
from SOWLAPP.views import *
from CATALOG.views import *
Try to render main page without those modules imported in the urls.py
Also please provide your project settings.py config. That is under section INSTALLED_APPS. There might be an app that has no urls.py and something is referring there. But it's last case that may be... (IMHO)
As the second thought you might have the corrupted/changed Django or/and some apps redistributable version... Check if you installed them via automatic scripts. They rarely have serious bugs.
Related
I am working through a (mycodesmells) django tutorial and towards the bottom under "ADDING TO THE PROJECT" it says to update the url.py file with the code that it gives.
Once I update that file it crashes the server and gives me the error.
"No module named 'django_simple.todo'
I looked in SO posts and template view and redirect were mentioned in the following post.
1. Does this mean its deprecated?
2. How do i fix or adjust the code for Django 1.1 and Python 3
Templateview
from django.conf.urls import include, url
from django.contrib import admin
from django_simple.todo import views as todo_views
admin.autodiscover()
urlpatterns = [
url(r'^$', todo_views.index),
url(r'^admin/', include(admin.site.urls)),
]
Make sure you have an __init__.py file in the "todo" folder. That lets Python know it's a module.
Also make sure you have django_simple.todo in your Django apps list in your settings.py.
I installed docutils.
Then included 'django.contrib.admindocs' in my 'INSTALLED_APPS',
Then, added 'admin/doc' to my url.
When I go to admin/doc, I see the list of things like models, views, filters and etc. It is fine. But when I click on one of those, it says page not found.
Where did I go wrong?
i know this question is for long time ago but :
Add path('admin/doc/', include('django.contrib.admindocs.urls')) to your urlpatterns.
1
Make sure it’s included before the 'admin/' entry, so that requests to /admin/doc/ don’t get handled by the latter entry.
if you code like this:
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('admin/doc/', include('django.contrib.admindocs.urls')),
]
change it to:
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/doc/', include('django.contrib.admindocs.urls')),
path('admin/', admin.site.urls),
]
The Django admin documentation generator
I'm developing a webpage with Django.
I want to add/define an url for the application.
At this moment the url (dsvd/) doen't work properly. It shows only table data but no css and background.
here is the code for the main urls.py file.
from django.conf.urls import patterns, include, url
from django.conf import settings
from django.conf.urls.static import static
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'kleedkamer_overview.views.home', name='home'),
# url(r'^blog/', include('blog.urls')),
url(r'^admin/', include(admin.site.urls)),
url(r'^', include('kleedkamer_overview.urls')),
url(r'^dsvd/', 'kleedkamer_overview.views.indeling'),
)
and here the code inside the application urls.py file
from django.conf.urls import patterns, url
from kleedkamer_overview import views
urlpatterns = patterns ('',
url(r'^$',views.indeling, name='indeling'),
)
Is there anyone who can help me find the problem?
Greetz.
It looks like line is giving you trouble:
url(r'^dsvd/', 'kleedkamer_overview.views.indeling')
It seems like you are trying to map this URL to kleedkamer_overview.views.indeling but the URL regrex does not end with a '$'. Urls.py files that are mapped to other apps look like this:
url(r'^admin/', include(admin.site.urls))
Notice the include function call and that the regrex expression r'^admin/' does not end with a $
However mapping to a specific view is a bit different and it looks like this:
url(r'^$', 'kleedkamer_overview.views.home', name='home')
Notice that this time, where the include() function call would go you are instead telling Django which specific view you want to use and that the site regrex is r'^$' ending with a $.
Try changing this:
url(r'^dsvd/', 'kleedkamer_overview.views.indeling')
to this:
url(r'^dsvd/$', 'kleedkamer_overview.views.indeling')
Edit:
I saw your comments and while the urls.py is not the source of your problem, what I said is still valid because the urls.py was malformed. You should not even have the offending line there at all because you have already included the urls.py from kleedkamer_overview , there is no need to include it twice. It isn't DRY and it is just bad practice in general. This is why this still works despite being malformed because sites are looked for in order, in this case first it looks for /admin then / and does not reach /dsvd because it was already caught by / and your malformed url mapping is NEVER reached.
I recently upgraded from an ancient version of Django to 1.6.8, and now I am getting the error described above inconsistently (more on that below).
I've seen several threads here that discuss this error, and the culprit usually seems to be a view that calls reverse() somewhere. However, nothing in any of my views does this.
In fact, I can trim my site's urls.py to just the admin site...
from django.conf.urls import patterns, include, url
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'Site-main.views.home', name='home'),
# url(r'^Site-main/', include('Site-main.foo.urls')),
# Uncomment the admin/doc line below to enable admin documentation:
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# This has to go before the admin site
url(r'^a/', include(admin.site.urls)),
)
...and I still get the error periodically.
"Periodically?"
Well, that's the other really weird thing here. Around half the time the page loads as expected, with no errors. The rest of the time I get the error.
Another odd thing: if I use the manage.py server instead of apache+wsgi, the error seems to go away, but I've had the admins completely re-start apache with no change, so I don't think it's just an old and confused httpd process causing the problem.
Does anyone have ideas?
I am trying to develop a job portal in Django. As I am new to Django, I am not able to figure out why import error is getting displayed upon page hit, after deploying it on server. It was however working fine when I was running and testing in eclipse environment.
Here is the project tree structure for your reference. I know its quite long.
As you can see, MeraJob is the main project name and accounts, companies, MeraJob, students are applications inside it.
I deployed this structure and when I hit, I get this error.
I have ensured all the urls.py files have imported views.py using from views import * or simply import views. I can't figure out what the problem is, can someone help me out in this regard? Thanks in advance.
EDIT
Here is the my MeraJob/urls.py
from django.conf.urls import patterns, include, url
from django.contrib import admin
from . import views
import settings
admin.autodiscover()
urlpatterns = patterns('',
url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
url(r'^admin/', include(admin.site.urls)),url(r'^login/$', 'django.contrib.auth.views.login', name='login_view'),url(r'^password/reset/$', 'django.contrib.auth.views.password_change'),
url(r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.STATIC_ROOT }),
url(r'^logout/$', logout_page),
url(r'^accounts/password/reset/$', 'django.contrib.auth.views.password_change'),
url(r'^password-changed/$', 'django.contrib.auth.views.password_change_done'),
url(r'^$', main_page),
url(r'^contact/$', contact_page),
url(r'', include('companies.urls')),
url(r'', include('miscellaneous.urls')),
url(r'', include('students.urls')),
)
Silly problem!
I missed to observe that the python file (views.py) didn't have read permissions for others!
Did a chmod appropriately and it worked! Thanks for other suggestions!!!
try from . import views
it would be easier if you posted your urls.py