Re: Django import error (Please reply soon)
Add 'myapp' to your INSTALLED_APPS in settings.py, right now Django doesn't know that myapp is an existing package. On Thursday, June 20, 2013 3:06:12 AM UTC-4, sanju wrote: > > > > Hi I have problems with import error in django. Tried looking > > into all possible solutions in Google, but in vain.I am posting my files > > here.Please look into it and correct it as soon as possible.Thanks in > Advance! > > This is my hierarchy: > c:/Users/Sanju/ > > mysite >-myapp > -> _init_.py > -> models.py > -> views.py > -> test.py >-mysite > -> settings.py > -> urls.py > -> wsgi.py >-manage.py > > Contents of manage.py > > #!/usr/bin/env python > import os > import sys > > if __name__ == "__main__": > os.environ.setdefault("DJANGO_SETTINGS_MODULE", > > "mysite.settings") > > from django.core.management import > > execute_from_command_line > > execute_from_command_line(sys.argv) > > sys.path.insert(0,'C:\Users\Sanju\mysite' ) > > > Contents of settings.py > > # Django settings for mysite project. > > DEBUG = True > TEMPLATE_DEBUG = DEBUG > > ADMINS = ( > # ('Your Name', 'your_...@example.com '), > ) > > MANAGERS = ADMINS > > DATABASES = { > 'default': { > 'ENGINE': 'django.db.backends.mysql', # Add > > 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'. > 'NAME': 'mydemodb', # Or path to database > > file if using sqlite3. > # The following settings are not used with sqlite3: > 'USER': 'root', > 'PASSWORD': '', > 'HOST': '', # Empty for localhost through > > domain sockets or '127.0.0.1' for localhost through TCP. > 'PORT': '', # Set to empty string for default. > } > } > > # Hosts/domain names that are valid for this site; required if > > DEBUG is False > # See > > https://docs.djangoproject.com/en/1.5/ref/settings/#allowed- > > hosts > ALLOWED_HOSTS = [] > > # Local time zone for this installation. Choices can be found here: > # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name > # 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 = 'America/Chicago' > > # Language code for this installation. All choices can be found > > here: > # http://www.i18nguy.com/unicode/language-identifiers.html > 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: "/var/www/example.com/media/" > MEDIA_ROOT = '' > > # URL that handles the media served from MEDIA_ROOT. Make > > sure to use a > # trailing slash. > # Examples: "http://example.com/media/";, > > "http://media.example.com/"; > 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: "/var/www/example.com/static/" > STATIC_ROOT = '' > > # URL prefix for static files. > # Example: "http://example.com/static/";, > > "http://static.example.com/"; > STATIC_URL = '/static/' > > # Additional locations of static files > STATICFILES_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 = 'w07((nih+vm%^j1i&moh$t3ewrrt*)!&pliiog+%odi > > $_&4=w5' > > # 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 prote
Re: Project settings and application settings.
Django settings are meant to be immutable, so your issues might be stemming from the way you're changing settings at runtime. Most Django projects that need to adjust settings at runtime do so by keeping the mutable settings in the database (e.g. a separate app in the project), so that's an approach you could try. On Thursday, June 20, 2013 5:32:31 AM UTC-4, pii...@gmail.com wrote: > > Hello all, > > I want to have an application settings modifying the project settings but > it doesn't seems to work. > > For development purpose I need to authenticate users against my > application database. In Production > the authentication is done by Apache, it then sends the REMOTE_USER, > correctly. > > To realize the authentication in production, i am using one middleware, > and one backend as found in > django documentation. > > I would like to have only one setting in the project thesite/settings.py, > a boolean called EXTERNAL_AUTH, > controling the content of AUTHENTICATION_BACKENDS and MIDDLEWARE_CLASSES. > > The code modifying those two variables will stand in my application > my/settings.py, It would then look like this > > from django.conf import settings > if settings.EXTERNAL_AUTH == False: > # Disabling standard login/logout. > settings.LOGIN_REDIRECT_URL='/' > settings.LOGIN_URL='/my/accounts/login/' > settings.LOGOUT_URL='/my/accounts/logout/' > else: > settings.AUTHENTICATION_BACKENDS = ( > ('my.backends.LDAPUserBackend', ) + > settings.AUTHENTICATION_BACKENDS) > > # Insert LDAPUserMiddleware right after AuthenticationMiddleware > index = settings.MIDDLEWARE_CLASSES.index( > "django.contrib.auth.middleware.AuthenticationMiddleware") > settings.MIDDLEWARE_CLASSES = (settings.MIDDLEWARE_CLASSES[:index+1] + > ('my.backends.LDAPUserMiddleware', ) + > settings.MIDDLEWARE_CLASSES[index+1:]) > > EXTERNAL_AUTH is used at different locations in my application, for > example I use it to decide whether or not > I display the "change password" link. > > When I start testing, toggling EXTERNAL_AUTH, the behavior is fuzzy. It > inconsitently redirect me to the accounts/login > even if I'm authenticated through apache. I guess the middleware isn't > called but when I raise an error, the debug page > contradicts this. > > I'm a bit lost. Do you have any hint? > > Regards, > > > > -- 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+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. For more options, visit https://groups.google.com/groups/opt_out.
Re: File Path Question
What does your project directory tree look like? I suspect the error has to do with where your documents/ directory is located in relation to the working directory. Try loading the document using a path relative to your project root. -Jacky Tian On Friday, June 21, 2013 9:29:20 AM UTC-4, Nigel Legg wrote: > > New to Django(ish). I'm not sure whether my error is coding or OS related: > I am getting the following error message: > > IOError at /myapp/file_view/4/ > > [Errno 2] No such file or directory: 'documents/2013/06/20/testdata1.csv' > > Request Method: GET Request URL: > http://127.0.0.1:8000/myapp/file_view/4/ Django Version: 1.5.1 Exception > Type: IOError Exception Value: > > [Errno 2] No such file or directory: 'documents/2013/06/20/testdata1.csv' > > Exception Location: C:\stats_portal\myproject\myproject\myapp\fileview.py > in filedata, line 5 Python Executable: c:\python27\python.exe Python > Version: 2.7.5 Python Path: > > ['C:\\stats_portal\\myproject', > 'c:\\python27\\lib\\site-packages\\python_dateutil-1.5-py2.7.egg', > 'c:\\python27\\lib\\site-packages\\django_directupload-0.0.11-py2.7.egg', > 'C:\\windows\\system32\\python27.zip', > 'c:\\python27\\DLLs', > 'c:\\python27\\lib', > 'c:\\python27\\lib\\plat-win', > 'c:\\python27\\lib\\lib-tk', > 'c:\\python27', > 'c:\\python27\\lib\\site-packages'] > > Server time: Fri, 21 Jun 2013 14:09:20 +0100 > Is the file not found problem because the upload has recorded it as > documents/2013/06/... even though I am working on Windows, so python / > django should have ... documents\\2013\\06\\... etc? I am developing on > Windows, but will deploy on Linux. > Or have I made an error elsewhere? > > > Regards, > Nigel Legg > 07914 740972 > http://twitter.com/nigellegg > http://uk.linkedin.com/in/nigellegg > > -- 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+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. For more options, visit https://groups.google.com/groups/opt_out.
Re: File Path Question
Have you set your MEDIA_ROOT appropriately in settings.py? Since fileview.py is where your original exception originated, can you post the relevant parts of the source in that file (whatever function line 5 belongs to). Did you get the exception under runserver or a "real" webserver? You shouldn't need to change the slashes in your path, Python handles that for you. -Jacky Tian On Friday, June 21, 2013 11:34:16 AM UTC-4, Nigel Legg wrote: > > In the path shown in my previous email, documents is a subdirectory of the > media directory, which is set in settings.py. > > views.py: > from myproject.myapp.forms import DocumentForm > > def list(request): > # Handle file upload > if request.method == 'POST': > form = DocumentForm(request.POST, request.FILES) > if form.is_valid(): > newdoc = Document(docfile = request.FILES['docfile']) > newdoc.save() > > # Redirect to the document list after POST > return > HttpResponseRedirect(reverse('myproject.myapp.views.list')) > else: > form = DocumentForm() # A empty, unbound form > > # Load documents for the list page > documents = Document.objects.all() > > # Render list page with the documents and the form > return render_to_response( > 'myapp/list.html', > {'documents': documents, 'form': form}, > context_instance=RequestContext(request) > ) > > models.py: > from django.db import models > > class Document(models.Model): > docfile = models.FileField(upload_to='documents/%Y/%m/%d') > > this section works fine - ie files yesterday were uploaded to > c:\\\\myproject\\media\\documents\\2013\\06\\20\\file.csv. > I need now to be able to access them. This error suggests I need to > convert documents/%Y/%m/%d' to documents\\2013\\06\\20\\ to be able to do > so. Is that correct? > > Regards, > Nigel Legg > 07914 740972 > http://twitter.com/nigellegg > http://uk.linkedin.com/in/nigellegg > > > > On 21 June 2013 16:25, Jacky Tian > wrote: > >> What does your project directory tree look like? I suspect the error has >> to do with where your documents/ directory is located in relation to the >> working directory. Try loading the document using a path relative to your >> project root. >> >> -Jacky Tian >> >> >> >> On Friday, June 21, 2013 9:29:20 AM UTC-4, Nigel Legg wrote: >>> >>> New to Django(ish). I'm not sure whether my error is coding or OS >>> related: >>> I am getting the following error message: >>> >>> IOError at /myapp/file_view/4/ >>> >>> [Errno 2] No such file or directory: 'documents/2013/06/20/**testdata1.csv' >>> >>> Request Method: GET Request URL: http://127.0.0.1:8000/myapp/** >>> file_view/4/ <http://127.0.0.1:8000/myapp/file_view/4/> Django Version: >>> 1.5.1 Exception Type: IOError Exception Value: >>> >>> [Errno 2] No such file or directory: 'documents/2013/06/20/**testdata1.csv' >>> >>> Exception Location: >>> C:\stats_portal\myproject\**myproject\myapp\fileview.py >>> in filedata, line 5 Python Executable: c:\python27\python.exe Python >>> Version: 2.7.5 Python Path: >>> >>> ['C:\\stats_portal\\myproject'**, >>> 'c:\\python27\\lib\\site-**packages\\python_dateutil-1.5-**py2.7.egg', >>> >>> 'c:\\python27\\lib\\site-**packages\\django_directupload-**0.0.11-py2.7.egg', >>> 'C:\\windows\\system32\\**python27.zip', >>> 'c:\\python27\\DLLs', >>> 'c:\\python27\\lib', >>> 'c:\\python27\\lib\\plat-win', >>> 'c:\\python27\\lib\\lib-tk', >>> 'c:\\python27', >>> 'c:\\python27\\lib\\site-**packages'] >>> >>> Server time: Fri, 21 Jun 2013 14:09:20 +0100 >>> Is the file not found problem because the upload has recorded it as >>> documents/2013/06/... even though I am working on Windows, so python / >>> django should have ... documents\\2013\\06\\... etc? I am developing on >>> Windows, but will deploy on Linux. >>> Or have I made an error elsewhere? >>> >>> >>> Regards, >>> Nigel Legg >>> 07914 740972 >>> http://twitter.com/nigellegg >>> http://uk.linkedin.com/in/**nigellegg<http://uk.linkedin.com/in/nigellegg> >>> >>> --
Best practices for serving images?
I've got an app that serves galleries of user-uploaded photos, some of which can be quite large in size. I've been serving scaled thumbnails for most templates, but I need a higher resolutions for a detail page. These images will still be smaller than the size of original image, and I'm wondering if it's better practice to dynamically resize them server-side based on the width of the viewport, or to just serve the full-size images and scale with CSS? Thanks -Jacky Tian -- 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+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. For more options, visit https://groups.google.com/groups/opt_out.
Re: no style in admin pages; learning from djangobook.com
Are you using the development server with `python manage.py runserver`? If you are, the static files for the admin should just work. If they don't, you may have messed up something in your settings.py. Otherwise, if you're serving your project from a webserver like Apache or nginx, run `python manage.py collectstatic` to consolidate the admin static files into your STATIC_ROOT directory. You'll probably have to fiddle with your web server configuration to serve files from STATIC_URL from STATIC_ROOT before you get it to work. On Monday, July 1, 2013 9:05:31 AM UTC-4, Jared Nielsen wrote: > > Hi all, > Just getting started with Django. > I'm following the projects on djangobook.com. > After activating the admin interface I don't have .css styling. > I also have no idea how to enable it. > Any help is greatly appreciated. > 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+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. For more options, visit https://groups.google.com/groups/opt_out.
Re: Trouble with STATIC_URL in v1.5.2
I think the standard way of including static files in templates in 1.5+ is through the staticfiles app<https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/>. In particular, look at the documentation on the {% static %} template tag. Depending on how you've set up your STATIC_ROOT and STATICFILES_DIRS settings, it could be a trivial find/replace in all your templates to switch. Here's something that may help explain how the staticfiles app works: http://blog.xjtian.com/post/52685286308/serving-static-files-in-django-more-complicated-than (disclosure: I'm the author of the post). -Jacky Tian On Monday, September 16, 2013 3:43:04 PM UTC-4, Adam wrote: > > Maybe this is something well known. > > I'm using STATIC_URL in my templates. Worked perfectly in Django 1.4.x. > Upgraded to v1.5.2. Now STATIC_URL ONLY works when the DEBUG setting is > True. When set to False (For production), STATIC_URL is an empty string > in the template. > > Anybody have any idea why this might be happening or what to look at? > Everything that needs to be set for STATIC_URL is set, otherwise it > wouldn't have worked in v1.4.x in the first place. > > -- > Adam (ad...@csh.rit.edu ) > > > -- 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+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. For more options, visit https://groups.google.com/groups/opt_out.