skip to Main Content

I’m deploying a django app on a host with apache and cPanel. I think I did all the steps that django needs to deploy. Everything works fine except dome admin posts urls.
When I’m sending a form via post from the admin site, and one of its fields is a File that will be uploaded to a directory, the server responses me 404. Some info:
Python 3.5, Django 1.11.9
Error: 404 Not Found
When: sending any post form containing a Choose File field, even if the file isn’t mandatory.
The forms without files in their fields work fine. In production everything works perfect.
I have a symlink in the public_html folder to my media and static folders.
This error only shows in the admin page. I can upload file from the site without any problem
This is my code:
urls.py

urlpatterns = i18n_patterns(
url(r'^admin/', admin.site.urls),
url(r'^i18n/', include('django.conf.urls.i18n')),
url(r'^', include('myapp.urls')),
prefix_default_language=False)

settings.py

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

This is my first time hosting a website, so, sorry if I’m asking a dummy question, but I couldn’t find any solution, even here. Also, sorry for my English. Thanks for the future answers

EDIT
My non-admin forms work perfect. The problem is in the admin page. I edited my old question with the changes in bold

2

Answers


  1. It can be web server problem. Check your cPanel settings
    May be something wrong with your wsgi file location
    Check up some tutorial for more info.

    Login or Signup to reply.
  2. In case you are serving media files using django’s static file server, the urlpatterns variable in your project’s base urls.py file should be assigned in a specific order so that the i18n_patterns(...) assignment places before the static(...) url.

    you should do it like so:

    urlpatterns = i18n_patterns(
        url(r'^admin/', admin.site.urls),
        url(r'^i18n/', include('django.conf.urls.i18n')),
        url(r'^', include('myapp.urls')),
        prefix_default_language=False)
    
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search