[Django]-ImportError: No module named blog Django

3👍

Only the app name blog should be added in settings.py

settings.py

INSTALLED_APPS = [
    #Custom Apps
    'blog',
    . . .
    . . .

    #django apps
    'django.contrib.admin',
    'django.contrib.auth',
    . . . 
    . . . 
]

In urls.py

from .views import index, view_post, view_category

urlpatterns = [
    url(r'^$', index, name='view-blog-index'),
    url(r'^blog/view/(?P<slug>[^\.]+).html', view_post, name='view-blog-post'),
    url(r'^blog/category/(?P<slug>[^\.]+).html', view_category, name='view-blog-category'),
]

1👍

You should use this syntax when defining your urls:

from blog.views import index, view_post, view_category

urlpatterns = [
  url(r'^$', index, name='view-blog-index'),
  url(r'^blog/view/(?P<slug>[^\.]+).html', view_post, name='view-blog-post'),
  url(r'^blog/category/(?P<slug>[^\.]+).html', view_category, name='view-blog-category'),
]

Take a look at the Django documentation on this topic: link

Also, note that the official documentation recommends using hypens instead of underscores when naming your url patterns: link

Edit: as Astik pointed, you don’t need to put logicmindblog.blog in the INSTALLED_APPS, you can just put blog.

Leave a comment