WebFaction
Community site: login faq

Hi,

I have a custom WSGI app, to use Django 1.3-dev. When I try to get the current working directory inside my settings.py, using "os.getcwd()", it just returns me "/". How can I get the correct working directory?

Thanks,

Diogo

asked 27 Feb '11, 18:15

diogobaeder
312
accept rate: 0%


mod_wsgi will always use / as the CWD. If you want settings.py to know the directory in which it resides, you can do this:

from os.path import abspath, dirname
my_cwd = abspath(dirname(__file__))

You'll then have your settings' parent directory in my_cwd. Hope that helps!

permanent link

answered 27 Feb '11, 18:24

seanf
12.2k42136
accept rate: 37%

I've set "PWD" as environment variable, and it worked, but your hint is a lot clearer, so I dropped mine in favor of yours. :-)

Thanks!

(27 Feb '11, 19:35) diogobaeder
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×910
×63
×1

question asked: 27 Feb '11, 18:15

question was seen: 7,638 times

last updated: 27 Feb '11, 19:35

                              
WEBFACTION
REACH US
SUPPORT
LEGAL
© COPYRIGHT 2003-2021 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM