{"id":1995,"date":"2022-08-30T15:21:10","date_gmt":"2022-08-30T15:21:10","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/12\/08\/settings-module-not-found-deploying-django-on-a-shared-server-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:21:10","modified_gmt":"2022-08-30T15:21:10","slug":"settings-module-not-found-deploying-django-on-a-shared-server-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/settings-module-not-found-deploying-django-on-a-shared-server-collection-of-common-programming-errors\/","title":{"rendered":"Settings module not found deploying django on a shared server-Collection of common programming errors"},"content":{"rendered":"<p>I&#8217;m trying to deploy my django project on a shared hosting as describe here<\/p>\n<p>I have my project on \/home\/user\/www\/testa<\/p>\n<p>I&#8217;m using this script<\/p>\n<pre><code>\n#!\/usr\/bin\/python\nimport sys, os\n\nsys.path.append(\"\/home\/user\/bin\/python\")\n\nsys.path.append('\/home\/user\/www\/testa')\n\n\nos.chdir(\"\/home\/user\/www\/testa\")\n\nos.environ['DJANGO_SETTINGS_MODULE'] = \"settings.py\"\n\nfrom django.core.servers.fastcgi import runfastcgi\nrunfastcgi(method=\"threaded\", daemonize=\"false\")\n\n<\/code><\/pre>\n<p>And here&#8217;s the error I get when trying to run it from shell:<\/p>\n<pre><code>\nWSGIServer: missing FastCGI param REQUEST_METHOD required by WSGI!\nWSGIServer: missing FastCGI param SERVER_NAME required by WSGI!\nWSGIServer: missing FastCGI param SERVER_PORT required by WSGI!\nWSGIServer: missing FastCGI param SERVER_PROTOCOL required by WSGI!\nTraceback (most recent call last): File \"build\/bdist.linux-i686\/egg\/flup\/server\/fcgi_base.py\", line 558, in run File \"build\/bdist.linux-i686\/egg\/flup\/server\/fcgi_base.py\", line 1118, in handler File \"\/home\/user\/lib\/python2.4\/site-packages\/django\/core\/handlers\/wsgi.py\", line 230, in __call__ self.load_middleware() File \"\/home\/user\/lib\/python2.4\/site-packages\/django\/core\/handlers\/base.py\", line 33, in load_middleware for middleware_path in settings.MIDDLEWARE_CLASSES: File \"\/home\/user\/lib\/python2.4\/site-packages\/django\/utils\/functional.py\", line 269, in __getattr__ self._setup() File \"\/home\/usr\/lib\/python2.4\/site-packages\/django\/conf\/__init__.py\", line 40, in _setup self._wrapped = Settings(settings_module) File \"\/home\/user\/lib\/python2.4\/site-packages\/django\/conf\/__init__.py\", line 75, in __init__ raise ImportError, \"Could not import settings '%s' (Is it on sys.path? Does it have syntax errors?): %s\" % (self.SETTINGS_MODULE, e)\nImportError: Could not import settings 'settings.py' (Is it on sys.path? Does it have syntax errors?): No module named settings.py\nContent-Type: text\/html Unhandled Exception <br \/>An unhandled exception was thrown by the application.<br \/><br \/>\n\n\n<\/code><\/pre>\n<p>What am I doing wrong?<\/p>\n<p>Running the script from the browser just gives me an internal server error.<\/p>\n<ol>\n<li>\n<p>The line<\/p>\n<pre><code>os.environ['DJANGO_SETTINGS_MODULE'] = \"settings.py\"\n<\/code><\/pre>\n<p>should be more like<\/p>\n<pre><code>os.environ['DJANGO_SETTINGS_MODULE'] = \"settings\"\n<\/code><\/pre>\n<p>based on how you&#8217;re setting up <code>sys.path<\/code>. That environment variable is supposed to contain the path to the module <em>as it should be imported by Python<\/em>, not the actual filename of the module.<\/p>\n<p>Basically, the way you&#8217;ve got it now is making Django do something like this internally:<\/p>\n<pre><code>import settings.py\n<\/code><\/pre>\n<p>I.e., it&#8217;s trying to import a <code>py<\/code> module from inside a <code>settings<\/code> module.<\/p>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2013-12-08 05:40:03. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I&#8217;m trying to deploy my django project on a shared hosting as describe here I have my project on \/home\/user\/www\/testa I&#8217;m using this script #!\/usr\/bin\/python import sys, os sys.path.append(&#8220;\/home\/user\/bin\/python&#8221;) sys.path.append(&#8216;\/home\/user\/www\/testa&#8217;) os.chdir(&#8220;\/home\/user\/www\/testa&#8221;) os.environ[&#8216;DJANGO_SETTINGS_MODULE&#8217;] = &#8220;settings.py&#8221; from django.core.servers.fastcgi import runfastcgi runfastcgi(method=&#8221;threaded&#8221;, daemonize=&#8221;false&#8221;) And here&#8217;s the error I get when trying to run it from shell: WSGIServer: missing [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1995","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1995","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=1995"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1995\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=1995"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=1995"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=1995"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}