I have created Django project on godaddy cpanel shared hosting ,
www.example.com is working and everything working fine with images and html templates, but when I hit www.example.com/about or www.example.com/admin or any other url it gives 404.
here is my passenger_wsgi.py file
import website.wsgi
SCRIPT_NAME = '/home/udpo***j0so4/website'
class PassengerPathInfoFix(object):
def __init__(self, app):
self.app = app
def __call__(self, environ, start_response):
from urllib.parse import unquote
environ['SCRIPT_NAME'] = SCRIPT_NAME
request_uri = unquote(environ['REQUEST_URI'])
script_name = unquote(environ.get('SCRIPT_NAME', ''))
offset = request_uri.startswith(script_name) and len(environ['SCRIPT_NAME']) or 0
environ['PATH_INFO'] = request_uri[offset:].split('?', 1)[0]
return self.app(environ, start_response)
application = website.wsgi.application
application = PassengerPathInfoFix(application)
here is my settings.py file
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
SECRET_KEY = '****************'
DEBUG = True
ALLOWED_HOSTS = ['www.example.com','example.com']
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'home',
'django_user_agents',
'django_filters',
'django.contrib.sites',#django-allauth
'allauth', #django-allauth
'allauth.account', #django-allauth
'allauth.socialaccount',#django-allauth
'allauth.socialaccount.providers.google', #django-allauth
]
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',
]
ROOT_URLCONF = 'website.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'website.wsgi.application'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
# Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'database', # Or path to database file if using sqlite3.
'USER': 'user', # Not used with sqlite3.
'PASSWORD': 'password', # Not used with sqlite3.
'HOST': '166.**.**.**', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '3306', # Set to empty string for default. Not used with sqlite3.
}
}
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
STATIC_URL = '/static/'
MEDIA_URL = '/media/'
STATICFILES_DIRS = [BASE_DIR + '/assets',]
STATIC_ROOT = '/home/udpo***vj0so4/public_html/assets'
MEDIA_ROOT = '/home/udpo****vj0so4/public_html/media'
and here is my urls.py files
from django.contrib import admin
from django.urls import path,include
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('home.urls')),
path('accounts/', include('allauth.urls')),
]
and app urls.py files
from django.urls import path,include,re_path
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from . import views
from django.conf.urls import url
from django.urls import reverse
urlpatterns = [
path('aboutus/', views.intro, name='ab'),
path('frequent_questions/', views.fr_ques, name='fr_ques'),
re_path(r'^search=(?P<query>.+)$', views.search, name='search'),
path('Contact_us/', views.contact_view, name="contact"),
path('', views.home_1, name='homee'),
]
urlpatterns += staticfiles_urlpatterns()
I tried this solutions also but not worked for me.
2
Answers
I tried every possible solution but not any of them worked.
Than I changed to hosting provider and than it worked.
So i thought that it might be the hosting issue and i tried different godaddy hosting server from Asia to America and it also works for America Server.
Here I talked almost more than 3 days to godaddy's support team but they don't have knowledge possible reasons of this issue.
Check your root folder .htacces I added "RewriteEngine On" at the begging as pointed out in:
Redirect subfolder request to Passenger
and it worked