I am new to django and in the learning process. While doing some exercises, I came across some errors that I need help with.
Error: ImportError at / blog. No module named url
The urls.py file in the app called blog
from django.conf.urls.defaults import patterns, include, url from mysite.blog.views import archive urlpatterns = patterns('', url(r'^$',archive), )
Views.py file in an application called blog
# Create your views here. from django.template import loader, Context from django.http import HttpResponse from mysite.blog.models import Blogpost def archive(request): posts = BlogPost.objects.all() t = loader.get_template("archive.html") c = context({'posts': posts }) return HttpResponse(t.render(c))
The urls.py file in the mysite project
from django.conf.urls import patterns, include, url
Traceback:
File "D:\Super Developer\Python\lib\site-packages\django\core\handlers\base.py" in get_response 89. response = middleware_method(request) File "D:\Super Developer\Python\lib\site-packages\django\middleware\common.py" in process_request 67. if (not urlresolvers.is_valid_path(request.path_info, urlconf) and File "D:\Super Developer\Python\lib\site-packages\django\core\urlresolvers.py" in is_valid_path 531. resolve(path, urlconf) File "D:\Super Developer\Python\lib\site-packages\django\core\urlresolvers.py" in resolve 420. return get_resolver(urlconf).resolve(path) File "D:\Super Developer\Python\lib\site-packages\django\core\urlresolvers.py" in resolve 298. for pattern in self.url_patterns: File "D:\Super Developer\Python\lib\site-packages\django\core\urlresolvers.py" in url_patterns 328. patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module) File "D:\Super Developer\Python\lib\site-packages\django\core\urlresolvers.py" in urlconf_module 323. self._urlconf_module = import_module(self.urlconf_name) File "D:\Super Developer\Python\lib\site-packages\django\utils\importlib.py" in import_module 35. __import__(name) Exception Type: ImportError at /blog Exception Value: No module named urls
Project / application structure:
- Mysite
- manage.py
- init.py
- settings.py
- urls.py
- wsgi.py
- The blog
- init.py
- models.py
- views.py
- urls.py
- tests.py
- Templates - archive.html
Python path
['D: \ Super Developer \ Proj \ mysite', 'C: \ Windows \ system32 \ python27.zip', 'D: \ Super Developer \ Python \ DLLs,' D: \ Super Developer \ Python \ lib ',' D: \ Super Developer \ Python \ lib \ plat-win ',' D: \ Super Developer \ Python \ lib \ lib-tk ',' D: \ Super Developer \ Python ',' D: \ Super Developer \ Python \ lib \ site-packages']