1. 程式人生 > >記在新浪雲SAE部署django專案成功時心得

記在新浪雲SAE部署django專案成功時心得

1、關於新浪雲SAE的環境型別(以python為例)

      新浪雲SAE環境型別包括 “獨享環境” 和 “共享環境”。

      根據使用情況總結:

(1)“共享環境”

        python語言版本固定,不可指定。比如:當前預設python版本是2.7,而你的專案又可以改成基於python2.7,那就可恭喜你了;如果你的專案不可以改成就python2.7,那就折騰吧,我就被折騰了好幾個晚上。。。還是沒有搞定(誰要是知道怎麼解決,感激你能告訴我)。

       如果你的專案使用的django版本與環境不同(具體版本可度娘),可在專案使用django包方式解決。

(2)“獨享環境” 

         “共享環境”是免費部署的,在此要感謝新浪,給廣大開發者帶來福音!!!

         “獨享環境” 部署要付費,對於基礎開發者來說,費用還是比較低的;畢竟是收費的,服務果然不同,少了很多折騰。可以輕鬆指定python版本、django版本以及其他依賴包。

2、部署及其遇到的問題

(2)問題1(第一次提交版本git push):

以圖為證:

remote: -----> $ python manage.py collectstatic --noinput remote:        Traceback (most recent call last): remote:        File "manage.py", line 15, in <module> remote:        execute_from_command_line(sys.argv) remote:        File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line remote:        utility.execute() remote:        File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute remote:        self.fetch_command(subcommand).run_from_argv(self.argv) remote:        File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 316, in run_from_argv remote:        self.execute(*args, **cmd_options) remote:        File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 353, in execute remote:        output = self.handle(*args, **options) remote:        File "/app/.heroku/python/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 188, in handle remote:        collected = self.collect() remote:        File "/app/.heroku/python/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 114, in collect remote:        handler(path, prefixed_path, storage) remote:        File "/app/.heroku/python/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 343, in copy_file remote:        if not self.delete_file(path, prefixed_path, source_storage): remote:        File "/app/.heroku/python/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 249, in delete_file remote:        if self.storage.exists(prefixed_path): remote:        File "/app/.heroku/python/lib/python3.6/site-packages/django/core/files/storage.py", line 308, in exists remote:        return os.path.exists(self.path(name)) remote:        File "/app/.heroku/python/lib/python3.6/site-packages/django/contrib/staticfiles/storage.py", line 43, in path remote:        raise ImproperlyConfigured("You're using the staticfiles app " remote:        django.core.exceptions.ImproperlyConfigured: You're using the staticfiles app without having set the STATIC_ROOT setting to a filesystem path. remote: remote:        !     Error while running '$ python manage.py collectstatic --noinput'. remote:        See traceback above for details. remote: remote:        You may need to update application code to resolve this error. remote:        Or, you can disable collectstatic for this application: remote: remote:        $ heroku config:set DISABLE_COLLECTSTATIC=1 remote: remote:        https://devcenter.heroku.com/articles/django-assets remote: {"Code":1,"Error":"build image failed: exit status 1."} remote: 錯誤:構建映象失敗 remote: error: hook declined to update refs/heads/master

解決方法1:

因為沒有對setting.py設定STATIC_ROOT,解決如下:

STATIC_ROOT = os.path.join(BASE_DIR,'static')