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.
Related
I am watching this video to learn more about Django https://www.youtube.com/watch?v=v7xjdXWZafY
my code is exactly like his however I am getting an import error. It says "no modules named urls"
This is my code:
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('weather.urls')),
]
You do need to create a file called urls.py within your weather app. You can find further details on the documentation.
I am extremely new to programming. I searched and found a few similar threads here, though unfortunately the answers in those threads didn't seem to fix my own issue.
Problem
I am working my way through the Django tutorials, and I am on the third tutorial:
https://docs.djangoproject.com/en/1.7/intro/tutorial03/
I'm not sure if this matters, but I am working on a Macintosh w/ Mavericks.
The root directory in which I am working is 'Test2'. The directory structure is:
/Users/me/src/collact/collact/test2/
Within 'test2', and per the previous two tutorials, I have '/polls' and '/templates' folders.
My polls/views.py file has the following text:
from django.http import HttpResponse
def index(request):
return HttpResponse("Hello, world. You're at the polls index.")
My polls/urls.py file has the following text:
from django.conf.urls import patterns, url
from polls import views
urlpatterns = patterns('',
url(r'^$', views.index, name='index'),
)
Finally, in /test2/, I have a urls python file as well (.py). It has the text:
from django.conf.urls import patterns, include, url
from django.contrib import admin
urlpatterns = patterns('',
url(r'^polls/', include('polls.urls')),
url(r'^admin/', include(admin.site.urls)),
)
As far as I can tell, this is what the tutorial prescribes. Unfortunately, when I run the server using: python manage.py runserver, the website gives me an error/404 message:
Page not found (404)
Request Method:
GET Request
URL: http://localhost:8000/polls/ Using the URLconf defined in
test2.urls, Django tried these URL patterns, in this order: ^admin/
The current URL, polls/, didn't match any of these. You're seeing this
error because you have DEBUG = True in your Django settings file.
Change that to False, and Django will display a standard 404 page.
Does anyone have any idea how I can fix this? I know that this is a really stupid question, but I have been trying to figure it out for the past day or two, and unfortunately I'm just not familiar enough with programming to solve this on my own.
I am following the Django 1.6 tutorial 3 (https://docs.djangoproject.com/en/1.6/intro/tutorial03/) and I have become stuck towards the beginning - "Writing your first view".
The Django tutorial first says to edit the views.py, which I have done as follows:
from django.http import HttpResponse
def index(request):
return HttpResponse("Hello, world. You're at the poll index.")
Then it says to create a urls.py in the same directory, which I have done. My urls.py looks like this:
from django.conf.urls import patterns, include, url
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r'^polls/', include('polls.urls')),
url(r'^admin/', include(admin.site.urls)),
)
The next instruction is to now check the URL http://localhost:8000/polls/ for the message 'Hello, world. You're at the poll index.' but my browser simply produces the Django 404 error - Page not found.
I'm sure I'm doing something pretty stupid but I can't what is wrong, I've tried restarting the python webserver. I've followed the previous 2 tutorials with success, can anybody help me out?
If it makes a difference, I'm using Windows7, Python 3.4.1 and Django 1.6.5
Your view.py for polls must be in projectname/polls/ directory when first urls.py will be in projectname/projectname/.
Then, if you decide to configure and add more polls app specific urls, you can create urls.py in projectname/polls/.
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
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.