0

I am trying to deploy my django app on python anywhere, but I believe media_urls or media_root may be set incorrectly. I also spent time trying to figure out how to print all valid urls on django, but nothing work for me on this link. Django : How can I see a list of urlpatterns?.

I received a "ModuleNotFoundError: No module named 'django.core.urlresolvers'"

from .base import *

DEBUG = False

ALLOWED_HOSTS = ["*"]

MEDIA_ROOT = os.path.join(BASE_DIR, "images")
MEDIA_URL = '/snapcapsule/'
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, "static")

Picture of me setting the path on pythonanywhere Picture to get request for image

Answer

Answer

Rahmi Pruitt
  • 569
  • 1
  • 8
  • 28
  • Perhaps this could help https://stackoverflow.com/questions/43139081/importerror-no-module-named-django-core-urlresolvers – Monish K Nair Jul 10 '18 at 02:42
  • in server you do DEBUG = False so you need nginx and add url in url paterns you can find more answer on django documentation https://docs.djangoproject.com/en/2.0/howto/static-files/ – Maulik Harkhani Jul 10 '18 at 04:54

2 Answers2

2

Your static file mapping for images is at at /images, but you're accessing the image from /snapcapsule/images. Either change your media_url or your static file mapping so that they match.

Glenn
  • 7,262
  • 1
  • 17
  • 23
1

Most of the time, I server static and media with django at local and with nginx in server.

At local:

# at the end of urls.py
if settings.DEBUG:
    # debug toolbar
    import debug_toolbar

    urlpatterns.insert(0, path("__debug__/", include(debug_toolbar.urls)))

    # static and media
    from django.conf.urls.static import static
    from django.contrib.staticfiles.urls import staticfiles_urlpatterns

    urlpatterns.extend(
        staticfiles_urlpatterns()
        + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
    )

In server:

# nginx.conf
server {
    ...
    location /static/ {
        alias /path/to/project/static_collection/;
    }

    location /media/ {
        alias /path/to/project/media/;
    }
}
Waket Zheng
  • 5,065
  • 2
  • 17
  • 30
  • I don't think you use nginx with pythonanywhere. It has it on method of displaying media content – Rahmi Pruitt Jul 11 '18 at 04:25
  • My media root and url are all ok, but I was facing this same problem due to the nginx configuration. Thanks. – ni8mr Jun 09 '19 at 09:10