问题
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