简体   繁体   English

如何将Django项目迁移到Pythonanywhere

[英]How to migrate Django project to Pythonanywhere

I am trying to set up a Django app on Pythonanywhere — I've managed to figure out Bitbucket and clone the code in — I deleted the files in the directory that was provided for me — but can't get it to work. 我正在尝试在Pythonanywhere上设置一个Django应用程序 - 我已经设法找出Bitbucket并克隆代码 - 我删除了为我提供的目录中的文件 - 但无法让它工作。

I've done 'syncdb', then when I go to what I think is the correct URL for the app, I keep getting "Unhandled exception" — The error is that it can't find 'portfolio.settings' in an import (portfolio is the name of the app) 我已经完成'syncdb',然后当我转到我认为应用程序的正确URL时,我一直得到“未处理的异常” - 错误是它无法在导入中找到'portfolio.settings'(组合是应用程序的名称)

I also have no idea what to put for MEDIA_ROOT and STATIC_DIRS — these should be, as far as I know, full paths, not relative. 我也不知道要为MEDIA_ROOT和STATIC_DIRS添加什么 - 据我所知,这些应该是完整路径,而不是相对路径。

I'm a Django newbie, and this is proving rather overwhelming, to get the app, which functions fine locally, deployed. 我是一个Django新手,这证明是相当压倒性的,以获得在本地运行良好的应用程序,部署。 Any help much provided (I haven't found the Pythonanywhere forums — which don't seem indexed -- or help all that helpful, I'm afraid) 提供的任何帮助(我没有找到Pythonanywhere论坛 - 似乎没有索引 - 或者帮助所有有用的,我害怕)

I also thought: why don't I let Pythonanywhere set up a blank project for me, but again, I don't know how to handle STATIC_DIRS and MEDIA_ROOT, and I don't really know how to make my project fit their setup. 我还想:为什么我不让Pythonanywhere为我设置一个空白项目,但是我又不知道如何处理STATIC_DIRS和MEDIA_ROOT,我真的不知道如何使我的项目适合他们的设置。

Thanks for any help. 谢谢你的帮助。

For anyone else that runs into similar issues: import errors in web applications are typically to do with your sys.path not being correctly configured. 对于遇到类似问题的其他任何人:Web应用程序中的导入错误通常与您的sys.path未正确配置有关。 Check your WSGI file (on PythonAnywhere, you can find it on your web tab. Other hosts may do things differently). 检查您的WSGI文件(在PythonAnywhere上,您可以在Web选项卡上找到它。其他主机可能以不同的方式执行操作)。

Example: 例:

  • /home/myusername/myproject/ is the project folder /home/myusername/myproject/是项目文件夹
  • /home/myusername/myproject/my_cool_app/ is one of your app folders /home/myusername/myproject/my_cool_app/是您的app文件夹之一
  • /home/myusername/myproject/myproject/settings.py is the settings file location /home/myusername/myproject/myproject/settings.py是设置文件的位置

Your WSGI file should have: 您的WSGI文件应该具有:

sys.path.append('/home/myusername/myproject')
# ...
DJANGO_SETTINGS_MODULE = 'myproject.settings'

And your settings.py should have 你的settings.py应该有

INSTALLED_APPS = (
   #...
   'my_cool_app'

Everything has to line up so that the dot-notation names of your app in INSTALLED_APPS and your DJANGO_SETTINGS_MODULE environment variable will import correctly, relative to the folder you add to sys.path. 所有内容都必须排成一行,以便相对于添加到sys.path的文件夹, INSTALLED_APPS中的应用程序的点符号名称和DJANGO_SETTINGS_MODULE环境变量将正确导入。

So in the example above, you could conceivably do: 所以在上面的例子中,你可以想象:

# wsgi file
sys.path.append('/home/myusername')
DJANGO_SETTINGS_MODULE = 'myproject.myproject.settings'
# settings.py
INSTALLED_APPS = 'myproject.my_cool_app'

But don't do that, it's overcomplicated. 但是不要这样做,它太复杂了。

PS there's a detailed guide to sys.path and import issues for pythonanywhere in the docs. PS有一个详细的sys.path指南和文档中pythonanywhere的导入问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Django 如何部署项目 pythonanywhere.com - Django How to Deploy Project pythonanywhere.com 如何部署对我在 pythonanywhere 上托管的 django 项目所做的更改? - How to deploy changes made to my django project, which is hosted on pythonanywhere? 如何将 Django 应用程序覆盖到 Pythonanywhere? 3 - How to overwrite Django app to Pythonanywhere? 3 如何将 Django 应用程序覆盖到 Pythonanywhere? - How to overwrite Django app to Pythonanywhere? 如何在pythonanywhere项目中正确指定chromedriver的路径 - How to correctly specify the path to chromedriver in pythonanywhere project 如何在 pythonanywhere 上运行 django-made venv? - How to run django-made venv on pythonanywhere? 如何将现有的Django应用程序/项目部署/迁移到Heroku上的生产服务器? - How to deploy / migrate an existing django app / project to a production server on Heroku? 在pythonanywhere上部署的django项目中链接静态文件时出错 - Error in linking static files in django project deployed on pythonanywhere 如何将远程 postgres db 迁移到我的本地 django 项目中? - How to migrate remote postgres db into my local django project? 在pythonanywhere上部署Django项目时,不会加载Admin CSS - Admin css won't load when deploying Django project on pythonanywhere
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM