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
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'm very new in django and I am in deploying phase of a project. But after all setup, it shows 500 internal server error and the apache2 error log says ImportError: No module named 'backend'
I tried to edit wsgi.py as I thik this is the one giving this error
this is content of my wsgi.py file
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings.dev')
application = get_wsgi_application()
settings/dev.py
DEBUG = True
ALLOWED_HOSTS = ['my_ip_address']
WSGI_APPLICATION = 'backend.wsgi.application'
manage.py
import os
import sys
if __name__ == '__main__':
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings.dev')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
Directory Structure:
atms
--backend
--wsgi.py
--urls.py
--settings
--dev.py
--manage.py
pip freeze:
cairocffi==0.9.0
CairoSVG==2.2.1
cffi==1.11.5
cssselect2==0.2.1
defusedxml==0.5.0
Django==2.1.5
django-countries==5.3.2
django-weasyprint==0.5.4
djangorestframework==3.9.1
gunicorn==19.9.0
html5lib==1.0.1
Pillow==5.4.1
pycparser==2.19
Pyphen==0.9.5
pytz==2018.9
six==1.12.0
tinycss2==0.6.1
WeasyPrint==44
webencodings==0.5.1
whitenoise==4.0
atms.conf in /etc/apache2/sites-avalible
Alias /static /home/atms/atms/public/static
<Directory /home/atms/atms/public/static>
Require all granted
</Directory>
Alias /media /home/atms/atms/media
<Directory /home/atms/atms/media>
Require all granted
</Directory>
<Directory /home/atms/atms/backend>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIScriptAlias / /home/atms/atms/backend/wsgi.py
WSGIDaemonProcess django_app python-path=/home/atms/atms/backend python-home=/home/atms/venv
WSGIProcessGroup django_app
the error log says
ImportError: No module named 'backend'
You've put backend directly on your python-path, which means that is not itself an importable name. You should put the parent directory there instead:
WSGIDaemonProcess django_app python-path=/home/atms/atms python-home=/home/atms/venv
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'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.)
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.