skip to Main Content

i am having a problem uploading files to my server (shareserver) in cpanel.

when I upload a file either by admin or by a view it responds 404

if someone has help I would be very grateful

settings

DEBUG = True
STATIC_URL = '/static/'
STATIC_ROOT  =   os.path.join(BASE_DIR, 'staticfiles')

# STATICFILES_DIRS = (os.path.join(BASE_DIR, 'static/'),)

MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'static/media/')

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'),
    os.path.join(BASE_DIR, 'media'),
)

STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

MIDDLEWARE = [
    'whitenoise.middleware.WhiteNoiseMiddleware', ...

urls

...] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT, show_indexes= True
) + static(
    settings.STATIC_URL, document_root=settings.STATIC_ROOT
)

model

class Product(models.Model):
    name = models.CharField(max_length=50)
    produc_pic = models.ImageField(default = '',null=True, blank=True)

.htaccess

<IfModule Litespeed>

WSGIScriptAlias / /home/ibhfrwld/ferre-bianconeri/ferreteria-bianconeri/ferre/wsgi.py

<Directory /home/ibhfrwld/ferre-bianconeri/ferreteria-bianconeri/ferre>
<Files wsgi.py>
Require all granted
</Files>
</Directory>

Alias /media/ /home/ibhfrwld/ferre-bianconeri/ferreteria-bianconeri/media/
Alias /static/ /home/ibhfrwld/ferre-bianconeri/ferreteria-bianconeri/static/

<Directory /home/ibhfrwld/ferre-bianconeri/ferreteria-bianconeri/static>
Require all granted
</Directory>

<Directory /home/ibhfrwld/ferre-bianconeri/ferreteria-bianconeri/media>
Require all granted
</Directory>

</IfModule>

*************** directory tree ****************

3

Answers


  1. Chosen as BEST ANSWER

    do not apply exactly this solution in this thread Django admin 404 error when creating or editing a model instance nor the one you suggest but if I talk to him support team and I asked them to deactivate the "modsec" that was previously available in cpanel, they ask you why and you tell them that due to the incompatibility with django and voila, if you need to activate it again, you contact them again.

    after this everything worked correctly


  2. I find solution here,
    https://smartlazycoding.com/django-tutorial/deploy-a-django-website-to-a2-hosting
    I encounter the same issue. It was causes by passenger_wsgy.py. Initially I was only used

    from mysite.wsgi import application

    it won’t work, so I uses the code below, It work fine for me

    import os
    import sys
    # Set up paths and environment variables
    sys.path.append(os.getcwd())
    os.environ['DJANGO_SETTINGS_MODULE'] = 'project_name.settings'
    
    import django.core.handlers.wsgi
    from django.core.wsgi import get_wsgi_application
    
    SCRIPT_NAME = os.getcwd()
    
    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 = get_wsgi_application()
    application = PassengerPathInfoFix(application)
    
    Login or Signup to reply.
  3. We’re sorry, but something went wrong.
    The issue has been logged for investigation. Please try again later.

    I got the above error after changing from my_project.wsgi import application
    To yours I still get the same error.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search