I am newbie in Amazon Web Services and I'm trying to deploy a Django application using elastic BeansTalk. I'm following the AWS developer guide and when I deploy the application using EBCLI and open the browser to see my application running, I get the following error.
Request Method: GET Request URL: http://django-env.vsvztq2hxp.us-west-1.elasticbeanstalk.com/
Django Version: 1.9.12 Python Version: 3.4.3 Installed Applications:
['django.contrib.admin', 'django.contrib.auth',
'django.contrib.contenttypes', 'django.contrib.sessions',
'django.contrib.messages', 'django.contrib.staticfiles'] Installed
Middleware: ['django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware']
Traceback:
File "/opt/python/run/venv/lib/python3.4/site-packages/django/core/handlers/base.py" in get_response
123. response = middleware_method(request)
File "/opt/python/run/venv/lib/python3.4/site-packages/django/middleware/common.py" in process_request
56. host = request.get_host()
File "/opt/python/run/venv/lib/python3.4/site-packages/django/http/request.py" in get_host
109. raise DisallowedHost(msg)
Exception Type: DisallowedHost at /
Exception Value: Invalid HTTP_HOST header: 'django-env.vsvztq2hxp.us-west-1.elasticbeanstalk.com'. You may need to add 'django-env.vsvztq2hxp.us-west-1.elasticbeanstalk.com' to ALLOWED_HOSTS.
Obviosly the application was deployed but for some reason the exception raises.
Can anybody help me, please?
You are privileged to get such a verbose error..
Exception Type: DisallowedHost at / Exception Value: Invalid HTTP_HOST
header: 'django-env.vsvztq2hxp.us-west-1.elasticbeanstalk.com'. You
may need to add 'django-env.vsvztq2hxp.us-west-1.elasticbeanstalk.com'
to ALLOWED_HOSTS.
Just add django-env.vsvztq2hxp.us-west-1.elasticbeanstalk.com to your ALLOWED_HOSTS in settings.py
Do something like this
#in settings.py
ALLOWED_HOSTS = [ 'django-env.vsvztq2hxp.us-west-1.elasticbeanstalk.com', ...]
Try this:
ALLOWED_HOSTS = ['us-west-1.elasticbeanstalk.com']
in your settings.py file
Here is a great checklist before you deploy in prod.
https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/
Related
I don't know if I am explaining my problem correctly but I can clarify with the following picture of my settings.py file
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# SECURITY WARNING: don't run with debug turned on in production!
# DEBUG = True
DEBUG = False
# ALLOWED_HOSTS = []
ALLOWED_HOSTS = ['sheryar-portfolio.herokuapp.com', '127.0.0.1']
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'pages',
'calculator',
'amino'
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
Now here in ALLOWED_HOSTS, I have declared two hosts.
The Heroku one is running perfectly whereas I am having some issues in the local one.
It seems like that my static folder is not being located by django as I can only see the HTML of my website in local server.
In short, I cannot see the CSS being applied to my website when I am including the local server in ALLOWED_HOST
I created a superuser for my site, but when I started the server and tried to connect to the localhost:8000/admin page, I got an ERR_CONNECTION_REFUSED (site cannot be reached) error, and the server stopped running.
urls.py :
urlpatterns = [
path('admin/', admin.site.urls),
path('',include('blog.urls'))
]
settings.py :
# Application definition
INSTALLED_APPS = [
'blog.apps.BlogConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
When I start the server, I get the below message:
Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
May 17, 2020 - 18:25:44
Django version 3.0.1, using settings 'django_project.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
same happened to me. I realized that i defined the path with / but i was writing localhost:8000/admin
path('admin/', admin.site.urls)
I should type admin/ localhost:8000/admin/
Check if the firewall is causing any problem. (If only admin page is causing this problem, then firewall is not causing any probelm.)
Make sure that you have made necessary changes in urls.py and views.py.
Project's urls.py should include
path('admin/', admin.site.urls), in urlpatterns list.
settings.py should include
INSTALLED_APPS = ['django.contrib.admin',
...#more apps
]`
Let me know if this is helpful.
I was facing the same problem .My vpn was causing the problem .Go to chrome menu >setting>advanced settings>here my vpn was controlling the proxy settings and just disabling it fixed the issue .All the best
Try cleaning browser cache and then refreshing.
Additionally, in case you have created a custom User model, make sure you
Register your custom user model in the admin.py of the app where you defined your custom user model (see https://developer.mozilla.org/en-US/docs/Learn/Server-side/Django/Admin_site#registering_models)
In the settings.py, define a variable AUTH_USER_MODEL = '<app-name>.<custom-user-model-name>'
you forgot to runserver! python manage.py runserver
Im following a guide on youtube to work with django. Unfortunately this guide is made for pre 2.0 django.
So the challenge is to create a app called "posts" that can be accessed by localhost/posts.
After creating the folder 'posts' and adding it to settings.py MIDDLEWARE like this:
MIDDLEWARE = [
'posts',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
python manage.py runserver fails
When commenting 'posts' out runserver succedes.
The problem is that Im so new to all of this that I don't even know what to search for.
try adding 'post' in INSTALLED_APPS inside settings.py like this:
INSTALLED_APPS = [
'post',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
and delete it from middleware.
You have to "install" all the apps you make
django 1.5
I have a eclipse windows development setup and a Linux Apache host.
I have to pull some user data from a WSDL. When I do this from eclipse it works like a charm but when I update the code on the Linux server I get an error message. 'sessionstore' object has no attribute 'type'
if result.opError != None:
pass
#do something to deal with this error IDk what.
else:
request.session['sID'] = result.opSessionID
request.session['role'] = result.opRole.upper()
request.session['type'] = result.opUserType.upper()
I have used the request.session['<name>'] in several places and never had an issue. I have tried clearsesions data and syncing the DB.
How do I get it to take the new session data?
Thanks
Environment:
Request Method: POST
Request URL: http://xxxx.com:8080/login/
Django Version: 1.5.1
Python Version: 2.7.3
Installed Applications:
('django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'django.contrib.admindocs',
'users',
'WorkOrder',
'Equipment')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware')
Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
115. response = callback(request, *callback_args, **callback_kwargs)
File "/usr/local/www/Django/Test/users/views.py" in login_user
102. request.session['type'] = result.opUserType.upper()
Exception Type: AttributeError at /login/
Exception Value: 'SessionStore' object has no attribute 'role'
I want to use django.contrib.auth.middleware.RemoteUserMiddleware for authentication as outlined here:
https://docs.djangoproject.com/en/dev/howto/auth-remote-user/
Question is, how can I test this in a dev environment where there is no Apache? i.e. can I set REMOTE_USER somehow in local settings?
EDIT (adding settings)
AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.RemoteUserBackend',
)
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.RemoteUserMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
)
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
...
)
Then I have this in my local_Settings:
os.environ['REMOTE_USER'] = "mmatyas"
I also tried the 'HTTP_REMOTE_USER' variant. Thanks!
The variable has to be set in the environment in which you start the dev server. usually it's just:
REMOTE_USER=myuser ./manage.py runserver
You can write some WSGI middleware and set it there, and then make sure the wsgi middleware wraps your django app in the wsgi stack. lots of tutorials around on writing wsgi middleware, it'll be a short one page of code. Easy-peasy-lemon-squeezy!
In your dev environment, you can set an environment variable in the same command prompt you use to start up your dev server.
Something like export REMOTE_USER="duncan" if on a Unixy machine.
You can also do this by editing your manage.py and setting os.environ['REMOTE_USER'] = "duncan"