Heroku - Django: Had to change every mentioning of `myproject` into `app` to get my site working. How to best avoid this in the future?

本秂侑毒 提交于 2019-12-24 00:59:28

问题


I just ran my website made with Django1.3 for the first time on Heroku. I had to change every mentioning of myproject into app(such as import myproject.core.views into import app.core.views in urls.py ) in order to make my website run without an importError.

I figure either:

  • I change the Heroku directory ($ heroku run pwd ouputs /app) /app into /myproject. How do I do this?
  • Use a general prefix. How would I would I do this the best way?
  • I should push my project from a directory lower?

Update

This is the file structure of my local and heroku directory: gist.github.com/3361637

Here is an example of the changes I had to make in urls.py: gist.github.com/3361686

The changes for the other files were exactly the same, just changing the name of my project

Update2

To mipadi:

Next to your proposed structure I changed my .git folder from this:

.
|-- myproject_django
    |-- core
        # etc.
    |-- manage.py
    |-- .git
    # etc
|-- requirements.txt

to this:

.
|-- myproject_django
    |-- core
        # etc.
    |-- manage.py
    # etc
|-- requirements.txt
|-- .git

and pushed the changes to heroku. But now the folders/files are mixed with the previous structure. I tried to delete these files using heroku run rm file_name but this doesn't work. Any ideas?


回答1:


According to Heroku's instructions (and every Django/Heroku project I've set up), the Django project should be at the top level, so, in your case, this:

.
|-- pykaboo_django
    |-- core
        # etc.
    |-- manage.py
    # etc
|-- requirements.txt

Then, you can just import by app name:

from core.models import *



回答2:


It looks like you should be referencing your module directly as core since it resides at the root of your project. So, in urls.py you should be importing like:

import core.views

instead of import app.core.views or import myproject.core.views



来源:https://stackoverflow.com/questions/11972817/heroku-django-had-to-change-every-mentioning-of-myproject-into-app-to-get

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!