On Thursday, December 20, 2012 at 6:57:42 PM UTC+5:30, djangobie wrote:
Hi, I have just started practicing a tutorial for buidling a basic blog ( http://www.djangorocks.com/tutorials/how-to-create-a- )basic-blog-in-django/starting- your-application.html Did exactly the same (except, using 'djangopractice' as project name instead of 'djangorocks')Actually It also did run twice, but than started showing ImportError.My files:--------------------**settings.py**--------------------# Django settings for djangopractice project.#import os, django#DJANGO_ROOT = os.path.dirname(os.path.realpath(django.__file__)) #SITE_ROOT = os.path.dirname(os.path.realpath('__file__')) DEBUG = TrueTEMPLATE_DEBUG = DEBUGADMINS = (# ('Your Name', 'your_...@example.com'),)MANAGERS = ADMINSDATABASES = {'default': {'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.'NAME': 'djangopractice', # Or path to database file if using sqlite3.'USER': 'root', # Not used with sqlite3.'PASSWORD': '1290', # Not used with sqlite3.'HOST': '', # Set to empty string for localhost. Not used with sqlite3.'PORT': '', # Set to empty string for default. Not used with sqlite3.}}# Local time zone for this installation. Choices can be found here:# although not all choices may be available on all operating systems.# In a Windows environment this must be set to your system time zone.TIME_ZONE = 'Asia/Karachi'# Language code for this installation. All choices can be found here:LANGUAGE_CODE = 'en-us'SITE_ID = 1# If you set this to False, Django will make some optimizations so as not# to load the internationalization machinery.USE_I18N = True# If you set this to False, Django will not format dates, numbers and# calendars according to the current locale.USE_L10N = True# If you set this to False, Django will not use timezone-aware datetimes.USE_TZ = True# Absolute filesystem path to the directory that will hold user-uploaded files.# Example: "/home/media/media.lawrence.com/media/ "MEDIA_ROOT = ''# URL that handles the media served from MEDIA_ROOT. Make sure to use a# trailing slash.# Examples: "http://media.lawrence.com/media/ ", "http://example.com/media/"MEDIA_URL = ''# Absolute path to the directory static files should be collected to.# Don't put anything in this directory yourself; store your static files# in apps' "static/" subdirectories and in STATICFILES_DIRS.# Example: "/home/media/media.lawrence.com/static/ "STATIC_ROOT = ''# URL prefix for static files.# Example: "http://media.lawrence.com/static/ "STATIC_URL = '/static/'# Additional locations of static filesSTATICFILES_DIRS = (# Put strings here, like "/home/html/static" or "C:/www/django/static".# Always use forward slashes, even on Windows.# Don't forget to use absolute paths, not relative paths.)# List of finder classes that know how to find static files in# various locations.STATICFILES_FINDERS = ('django.contrib.staticfiles.finders.FileSystemFinder', 'django.contrib.staticfiles.finders.AppDirectoriesFinder', # 'django.contrib.staticfiles.finders.DefaultStorageFinder', )# Make this unique, and don't share it with anybody.SECRET_KEY = '@io!2+0*rw1o0tjq%t5zb8e$v(wf3p#yk_8#lb^%hrerzijwt1' # List of callables that know how to import templates from various sources.TEMPLATE_LOADERS = ('django.template.loaders.filesystem.Loader', 'django.template.loaders.app_directories.Loader', # 'django.template.loaders.eggs.Loader', )MIDDLEWARE_CLASSES = ('django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware. AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', # Uncomment the next line for simple clickjacking protection:# 'django.middleware.clickjacking. XFrameOptionsMiddleware', )ROOT_URLCONF = 'djangopractice.urls'# Python dotted path to the WSGI application used by Django's runserver.WSGI_APPLICATION = 'djangopractice.wsgi.application' TEMPLATE_DIRS = ("/home/username/djangosites/djangopractice/Templates" # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".# Always use forward slashes, even on Windows.# Don't forget to use absolute paths, not relative paths.)INSTALLED_APPS = ('django.contrib.auth','django.contrib.contenttypes','django.contrib.sessions','django.contrib.sites','django.contrib.messages','django.contrib.staticfiles','django.contrib.admin','django.contrib.admindocs','blog',)# A sample logging configuration. The only tangible logging# performed by this configuration is to send an email to# the site admins on every HTTP 500 error when DEBUG=False.# more details on how to customize your logging configuration.LOGGING = {'version': 1,'disable_existing_loggers': False,'filters': {'require_debug_false': {'()': 'django.utils.log.RequireDebugFalse' }},'handlers': {'mail_admins': {'level': 'ERROR','filters': ['require_debug_false'],'class': 'django.utils.log.AdminEmailHandler' }},'loggers': {'django.request': {'handlers': ['mail_admins'],'level': 'ERROR','propagate': True,},}}--------------**urls.py**--------------from django.conf.urls import patterns, include, url# Uncomment the next two lines to enable the admin:from django.contrib import adminadmin.autodiscover()urlpatterns = patterns('',(r'^$', 'djangopractice.blog.views.index'), url(r'^blog/view/(?P<slug>[^\.]+).html', 'djangopractice.blog.views.view_post', name='view_blog_post'), url(r'^blog/category/(?P<slug>[^\.]+).html', 'djangopractice.blog.views.view_category', name='view_blog_category'),# Examples:# url(r'^$', 'djangopractice.views.home', name='home'),# url(r'^djangopractice/', include('djangopractice.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'^admin/', include(admin.site.urls)),)----------------**views.py**----------------from blog.models import Blog, Categoryfrom django.shortcuts import render_to_response, get_object_or_404def index(request):return render_to_response('index.html', { 'category': Category.objects.all(),'posts': Blog.objects.all()[:5]})def view_post(request, slug): #slug is mapped to, from the urls.pyreturn render_to_respomse('view_post.html', { 'post': get_object_or_404(Blog, slug=slug)})def view_category(request, slug):category = get_object_or_404(Category, slug=slug)return render_to_response('view_category.html' { 'category':category,'posts': Blog.objects.filter(category=category)[:5] })--------------------**models.py**-------------------from django.db import modelsfrom django.db.models import permalinkclass Blog(models.Model):title = models.CharField(max_length=100, unique=True) slug = models.SlugField(max_length=100, unique=True) body = models.TextField()posted = models.DateField(db_index=True, auto_now_add=True) category = models.ForeignKey('blog.Category') def __unicode__(self):return '%s' % self.title@permalinkdef get_absolute_url(self): #returns a url automatically calculating, based on urls.py paramreturn ('view_blog_post', None, { 'slug': self.slug})class Category(models.Model):title = models.CharField(max_length=100, db_index=True) slug = models.SlugField(max_length=100, db_index=True) def __unicode__(self):return '%s' % self.title@permalinkdef get_absolute_url(self):return ('view_blog_category', None, { 'slug': self.slug})------------------**admin.py**------------------from django.contrib import adminfrom blog.models import Blog, Category#class BlogAdmin(admin.ModelAdmin):# exclude = ['posted']# prepopulated_fields = {'slug': ('title',)}#class CategoryAdmin(admin.ModelAdmin): # prepopulated_fields = {'slug': ('title',)}#admin.site.register(Blog, BlogAdmin)#admin.site.register(Category, CategoryAdmin)admin.site.register(Blog)admin.site.register(Category)----------------------python manage.py validate0 errorsalso syncbd properly... but don't why not considering my app a modeule.my dir structure is:------------------------------------------------------------ ---------- djangopractice---djangopractice-- __init__.py- settings.py- urls.py- wsgi.py--blog-- models.py- views.py- admin.py- __init__.py- test.py--Templates-- base.html- index.html- view_category.html- view_posts.html------------------------------------------------------------ ------------- Exact error I am getting in the browser is:------------------------------------------------------ ImportError at /
No module named blog
Request Method: GET Request URL: http://localhost:8000/ Django Version: 1.4.3 Exception Type: ImportError Exception Value: No module named blogException Location: /usr/local/lib/python2.7/dist- packages/django/utils/ importlib.py in import_module, line 35 Python Executable: /usr/bin/python Python Version: 2.7.3 Python Path: ['/home/username/djangosites/djangopractice', '/usr/lib/python2.7', '/usr/lib/python2.7/plat- linux2', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib- dynload', '/usr/local/lib/python2.7/ dist-packages', '/usr/lib/python2.7/dist- packages', '/usr/lib/python2.7/dist- packages/PIL', '/usr/lib/python2.7/dist- packages/gst-0.10', '/usr/lib/python2.7/dist- packages/gtk-2.0', '/usr/lib/python2.7/dist- packages/ubuntu-sso-client', '/usr/lib/python2.7/dist- packages/ubuntuone-client', '/usr/lib/python2.7/dist- packages/ubuntuone-control- panel', '/usr/lib/python2.7/dist- packages/ubuntuone-couch', '/usr/lib/python2.7/dist- packages/ubuntuone-storage- protocol'] -----------------------------Thanks
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c2107bec-6f2d-46d2-87ae-2e9810a751d7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment