I'm deploying django on port 81 of my webserver. This is to get it off the development server, but I'm not ready to have it be served as the root on port 80.
The problem is that any time I try to access any page on port 81, I see the django error screen and it always says: ImportError at / No module named mysite.urls
httpd.conf
Listen 81
NameVirtualHost *:81
<VirtualHost *:81>
DocumentRoot /home/bill/Desktop/mysite
WSGIScriptAlias / /home/bill/Desktop/mysite/django.wsgi
<Directory /home/bill/Desktop/mysite>
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
/home/bill/Desktop/mysite/django.wsgi
import os
import sys
sys.path.append('/home/bill/Desktop/mysite')
os.environ['PYTHON_EGG_CACHE'] = '/home/bill/Desktop/mysite/.python-egg'
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
in mysite/settings.py
...
ROOT_URLCONF = 'mysite.urls'
...
I know for a fact that ROOT_URLCONF = 'mysite.urls' is getting loaded, because if I change it to anything else (like "test"), I get ImportError at / No module named test
Any thoughts about where this deployment has gone wrong? Thanks in advance!
Your deployment is fine. Your code needs to be corrected, in that it should only be importing (and subsequently using) urls.
(Although os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' is sort of redundant.)
Related
I'm developing a django website and am currently working on deploying. I'm following this tutorial. And im in the last stage of the tutorial (1:08:00 in the video). After he finished configuration th django-project.conf file he saves and everything is working, but me on the other hand, i get an:
Not Found
The requested URL / was not found on this server.
Apache/2.4.34 (Ubuntu) Server at **** Port 80
This is my projects .conf file:
<VirtualHost *:80>
ServerName _
Redirect 404 /
Alias /static /home/user/project/static
<Directory /home/user/project/static>
Require all granted
</Directory>
<Directory /home/user/project/project>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIScriptAlias / /home/user/project/project/wsgi.py
WSGIDaemonProcess project_app python-path=/home/user/project python-home=/home/user/project/venv
WSGIProcessGroup project_app
</VirtualHost>
This is my urls.py:
from django.contrib import admin
from django.urls import path, include
from . import views
urlpatterns = [
path('admin/', admin.site.urls),
path('', views.homepage),
path('rh/', views.rh, name="rh"),
path('gvt/', views.gvt, name="gvt"),
path('fth/', views.fth, name="fth"),
path('pages/', include('pages.urls')),
]
This is my wsgi.py
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'excelsite.settings')
application = get_wsgi_application()
sys.path.append('/home/alexholst/excelsite')
This is the error.log
(Couldnt copy, so i have this screenshot instead)
here
I tried to create a new django project on apache2, but I got 404 error.
Here are what I did.
-In /home/ubuntu/django directory, type
django-admin startproject proj
-Edit proj/proj/wsgi.py as follows.
import os
import sys
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'proj.settings')
sys.path.append('/home/ubuntu/django/proj');
sys.path.append('/home/ubuntu/django/proj/proj');
application = get_wsgi_application()
-Edit ALLOWED_HOSTS in proj/proj/settings.py as follows.
ALLOWED_HOSTS = ['example.com']
-Edit /etc/apache2/conf-available/wsgi.conf as follows.
WSGIScriptAlias /proj /home/ubuntu/django/proj/proj/wsgi.py
WSGIPythonPath /home/ubuntu/django/proj
<Directory /home/ubuntu>
Require all granted
</Directory>
<Directory /home/ubuntu/proj/proj>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
-Restart apache2 as
/etc/init.d/apache2 restart
-Access to http://example.com/proj, and then got 404 error as follows.
Page not found (404)
Request Method: GET
Request URL: http://example.com/proj/
Using the URLconf defined in proj.urls, Django tried these URL patterns, in this order:
admin/
The empty path didn't match any of these.
My enviroment is as follows.
Ubuntu 18.04 LTS (AWS)
Apache/2.4.29
Python 3.6.9
Django 3.0.5
How can I solve this 404 error?
Do you have '/admin' in your urls.py file?
You may also need to change the apache2 settings from /home/ubuntu/proj/proj to /home/ubuntu/django/proj/proj
I am running a site that was previously running on django 1.4, but now I shifted it on django 1.6.
I am able to run my site on both version using python manage.py shell.
I am running it nicely on Apache when i keep django 1.4 virtual environment python path in Apache site-enabled, but it does not work when i keep django 1.6 virtual environment python path there.
For django 1.6 it throws error:
ImproperlyConfigured: Requested setting DEBUG, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings
What can be problem? Any changes required in wsgi.py file for django 1.6? Please help.
my virtualhost file is :
<VirtualHost *:80>
ServerAdmin vidya.sagar0911#gmail.com
DocumentRoot /home/vidya/workspace/vidya/vidya_rose/cms/trunk/demo/
ServerName www.vidblog.com
<Directory /home/vidya/workspace/vidya/vidya_rose/cms/trunk/demo>
#Order deny,allow
#Allow from all
Options FollowSymLinks
AllowOverride None
</Directory>
Alias /media /home/vidya/workspace/vidya/vidya_rose/cms/trunk/demo/vidyamedia/
Alias /static /home/vidya/workspace/vidya/vidya_rose/cms/trunk/demo/static/
WSGIDaemonProcess www.demo.com user=www-data group=www-data processes=8 threads=75\
python-path=/home/vidya/workspace/djnago1.6/lib/python2.7/site-packages
WSGIProcessGroup www.vidblog.com
WSGIScriptAlias / /home/vidya/workspace/vidya/vidya_rose/cms/trunk/demo/demo/wsgi.py
</VirtualHost>
This is the issue when you are migrating your old projects from django-1.x(<1.6) to django-1.6 you need to define DJANGO_SETTINGS_MODULE before you call get_wsgi_application
import os
import sys
sys.path.append(os.path.dirname(os.path.dirname(__file__)))
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "yourproject.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
I get an 500 internal server error and in the log files it writes:
[Thu Jun 14 16:30:22 2012] [error] [client 127.0.0.1] ImportError: Could not import settings 'mysite.settings' (Is it on sys.path?): No module named mysite.settings
here is my httpd.conf:
ServerName localhost
<VirtualHost *:80>
ServerAdmin ttt#mysite.com
ServerName mysite.com
ServerAlias www.mysite.com
DocumentRoot /var/www/mysite/
LogLevel warn
WSGIDaemonProcess processes=2 maximum-requests=500 threads=1
WSGIScriptAlias / /var/www/mysite/mysite/wsgi.py
Alias /media /var/www/mysite/mysite/static/media/
</VirtualHost>
wsgi.py:
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
This problem is covered in both the mod-wsgi documentation http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango and the Django deployment documentation https://docs.djangoproject.com/en/1.4/howto/deployment/wsgi/modwsgi/ which note that the project must be on your Python path. You can use the WSGIPythonPath directive or set the python-path in your WSGIDaemonProcess directive from the Django documentation. Or you can add it to the sys.path in your wsgi file as the mod-wsgi docs state.
I have installed PyAMF, Django, Apache2, and mod_wsgi on a Mac OS X 10.6 machine. While developing the project I used Django development servier. I would like to continue to use http://localhost:8000/gateway or http://127.0.0.1:8000/gateway for the PyAMF gateway. I have my Flex project deployed on http://localhost and phpMyAdmin at http://localhost/phpmyadmin.They seem to work fine but I am not able to connect to the PyAMF gateway.
Here is my Apache setting:
<VirtualHost *:8000>
# Set this to 'warn' when you're done with debugging
LogLevel debug
CustomLog /var/log/apache2/pyamf-access.log combined
ErrorLog /var/log/apache2/pyamf-error.log
# PyAMF remoting gateway
WSGIScriptAlias /gateway /Library/WebServer/Documents/MyApp/django.wsgi
<Directory /Library/WebServer/Documents/MyApp>
WSGIApplicationGroup %{GLOBAL}
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Here is the content of the django.wsgi script
import os
import sys
path = '/Library/WebServer/Documents'
if path not in sys.path:
sys.path.append(path)
sys.path.append('/Library/WebServer/Documents/MyApp')
os.environ['PYTHON_EGG_CACHE'] = '/tmp'
os.environ['DJANGO_SETTINGS_MODULE'] = 'MyApp.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
import posixpath
def application(environ, start_response):
# Wrapper to set SCRIPT_NAME to actual mount point.
environ['SCRIPT_NAME'] = posixpath.dirname(environ['SCRIPT_NAME'])
if environ['SCRIPT_NAME'] == '/':
environ['SCRIPT_NAME'] = ''
return _application(environ, start_response)
I would appreciate any help.
Thanks
When you added separate VirtualHost on port 8000, did you also add to Apache configuration in appropriate place:
NameVirtualHost *:8000
Usually there would only be such a line for port 80.