I got a basic Django setup working on my webhost, then I copied it down to my local machine. Both my local and my remote are using the same version of Django, and the same database (Postgres) with the same exact settings.py.
The thing is, when I run manage.py runserver on my local, and then browse to localhost, I get:
ViewDoesNotExist at /
Could not import myapp.main. View is not callable.
The view does exist though, and works perfectly fine on my remote. When I look at the PYTHONPATH in the debug output it includes the base directory of my django setup, and the "main" app is in the INSTALLED_APPS in my settings.py.
Basically everything is setup the same as on my remote (except that the remote is using Apache and I'm using runserver), at least as far as I can tell, but they are behaving differently. Does anyone have any clue what could be wrong?
EDIT:
It turns out I'm an idiot, and one of my files (urls.py) on the server never made it in to the commit. As a result, my local file wasn't what I thought it was, and I failed to realize the problem. Once I updated urls.py everything worked.
put 'myapp' in your settings.py
INSTALLED_APPS = (
'myapp',
)
urls.py
url(r'^$', 'myapp.views.main', name='main'),
check that in views.py, a function named 'main' should be there
Related
When I try to run my server in Django it is not able to find my app track that I just created:
ModuleNotFoundError: No module named 'track'
I got the same message for the app I was working on previously. I also get error messages relating to bootstrap, the last one being this:
OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect: '<frozen importlib._bootstrap>'
I started noticing this once I removed the bootstrap configurations from another app I was working on. I just downloaded bootstrap and know very little about it, especially how it could stop a Django server from running and not recognizing my app.
Any ideas???
If you already created an app which is 'track' by this command: python manage.py startapp track, don't forget to add it to the installed apps on the settings.py.
example:
INSTALLED_APPS = [
'app1',
'track',
'app2'
]
Also don't forget the add "," after each app, last one doesn't matter.
I've been at this for hours and need help. Initially I thought it was because I had mistakenly done something small that caused it, so I deleted the app, and created everything - virtual env, heroku app, django projects/apps - fresh.
I get the same error.
I made a cookiecutter django app and deployed it to heroku. Everything goes smoothly until it's time to actually use the site.
When I run heroku open, I get the DisallowedHosts error:
DisallowedHost at /
Invalid HTTP_HOST header: 'MY-NEW-APP.herokuapp.com'. You may need to add 'MY-NEW-APP.herokuapp.com' to ALLOWED_HOSTS.
heroku config shows that DJANGO_ALLOWED_HOSTS=MY-NEW-APP.herokuapp.com. I don't overwrite it in my settings file.
I have import django_heroku and django_heroku.settings(locals()) in my settings file.
DJANGO_SETTINGS_MODULE is correctly set to that file.
What's more, I get a warning about DEBUG=True, when DEBUG=False in my settings file and in the heroku environment.
What am I missing? Are hyphens a bad thing? Should I be using herokuapp.com instead of the full URL?
Solved my own question. I just had to:
heroku config:set DJANGO_ALLOWED_HOSTS=.MY-NEW-APP.COM,MY-NEW-APP.herokuapp.com,.herokuapp.com
I'm on Django, but I'm not sure if it matters. Anyway, I get an Application Error, and when I check the logs I see the error:
ImportError: No module named redlibros.wsgi
And it is fine cause the wsgi file is not name "redlibros.wsgi", I don't even know where it gets that name. The module is named
WSGI_APPLICATION = 'letrasclub.wsgi.application' # on my settings
web: gunicorn letrasclub.wsgi --log-file - # on my procfile
and on my folders it looks like this:
LetrasClub
letrasclub
wsgi.py
templates
static
...
Any idea where to find the error?
EDIT
Ok, some extra info: I have a different repo, with a different Heroku remote. I copied that repo, changed the app, created a new Heroku remote and then pushed to the new one.
So, if I write
git remote -v
heroku https://git.heroku.com/letrasclub2.git (fetch)
heroku https://git.heroku.com/letrasclub2.git (push)
origin https://github.com/Alejoss/LetrasClub2.0.git (fetch)
origin https://github.com/Alejoss/LetrasClub2.0.git (push)
Looks fine, if I go to the old app location and write the same command I get the old remote, the one that is related to the "redlibros.wsgi" app, perfect.
Now, why when I try to push the new app to the new heroku remote, I get the error that means Heroku is looking for the Old wsgi file, I changed the wsgi name, I changed the Procfile, I changed the wsgi file declaration on the settings, what am I missing?
You look at wrong project.
You look at https://github.com/Alejoss/redlibros (I guess it's Your project), not at https://github.com/Alejoss/LetrasClub2.0
I have a problem setting my Django application for deployment on openshift and testing locally.
Here is my structure
root_folder/
my_project/
anoter_app/
urls.py
views.py
my_project/
settings.py
urls.py
views.py
manage.py
application.py (to tell openshift where my settings file is: my_project.myproject.settings)
So for it to work on the deployment server, in the settings, the ROOT_URL_CONF is:
myproject.myproject.urls
and in my url file, the view must be reached as myproject.myproject.views
But when I want to work locally, I have to change the ROOL_URL_CONF as myproject.urls
and the views are reached with myproject.views
How do I make it work both locally and on the deployment server with the same settings?
Thank you
Create a new file named local_settings.py, at the bottom of your settings.py add:
try:
import local_settings
except:
print 'CAUTION -- NOT USING LOCAL SETTINGS!'
Put any settings you need to override on your local environment in your local_settings.py file.
I resolved it, the problem was that the folder and the app had the same name.
I renamed the app and now i dont'have to do myproject.myproject
I want to remove the django.contrib.comments app from a project I'm working on. I tried:
$ python manage.py sqlclear django.contrib.comments
on the shell but got:
Error: App with label django.contrib.comments could not be found. Are
you sure your INSTALLED_APPS setting is correct?
I have double checked my INSTALLED_APPS setting and indeed django.contrib.comments is present.
Any suggestions on how to get around this?
The app_name is actually just the last element of the file path. So comments should work.
You could run
python manage.py reset app_name
Then remove app_name from your installed apps.