简体   繁体   中英

How to run Django project locally for Heroku

I have a Django project and the structure is as following,

在此处输入图片说明

在此处输入图片说明

Inside the Procfile , I have this code,

web: gunicorn team-app.wsgi --log-file -

This is the requirements.txt ,

appdirs==1.4.3
coreapi==2.3.0
coreschema==0.0.4
dj-database-url==0.4.2
Django==1.11
django-allauth==0.31.0
django-rest-auth==0.9.1
django-rest-swagger==2.1.2
djangorestframework==3.6.2
gunicorn==19.7.1
itypes==1.1.0
Jinja2==2.9.6
MarkupSafe==1.0
oauthlib==2.0.2
openapi-codec==1.3.1
packaging==16.8
pyparsing==2.2.0
python-openid==2.2.5
pytz==2017.2
requests==2.13.0
requests-oauthlib==0.8.0
simplejson==3.10.0
six==1.10.0
uritemplate==3.0.0
whitenoise==3.3.0

env is the virtualenv installed locally. When I enter in the root folder, team-app and run the command heroku local web , I get the following error,

在此处输入图片说明

在此处输入图片说明

So, the issue is ImportError: No module named team-app.wsgi and I believe the location of the Procfile or something is not correct. The wsgi.py file in the users_groups is as following,

"""
WSGI config for users_groups project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/1.11/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "users_groups.settings")

application = get_wsgi_application()

I can provide additional informations if required. How to solve this issue?

There are two problems here. The first is Django-related:

ImportError: No module named team-app.wsgi

Your wsgi.py file is located in the users_groups/ directory so your Procfile should reference users_groups.wsgi :

web: gunicorn users_groups.wsgi --log-file -

The name of the top-level directory that contains the entire project is irrelevant.

The second problem is Heroku-related. Heroku expects the Django directory to be the root of your repository. Moving Procfile into src/ , then running heroku local web should get you up and running locally.

When you deploy to Heroku you'll have to make sure your current src/ directory is your root directory. That may mean moving some files into src/ and recreating / refactoring your Git repository there, or it could mean moving everything that's currently in src/ up a level.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM