1

I got an error,

url(r'^media/(?P<path>.*)$',django.views.static.serve, {'document_root': settings.MEDIA_ROOT})
AttributeError: 'module' object has no attribute 'views'

urls.py

from django.conf import settings
from django.conf.urls import include, url
from django.conf.urls.static import static
from django.contrib import admin

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^accounts/', include('accounts.urls')),
    url(r'^api/', include('UserToken.urls')),
    url(r'^accounts/', include('accounts.urls', namespace='accounts')),
    url(r'^ResultJSON/', include('ResultJSON.urls')),
    url(r'^api/1.0/', include('accounts.api_urls', namespace='api')),
    url(r'^api/1.0/login/', include('accounts.apitoken_urls', namespace='apilogin')),

] +static(settings.MEDIA_URL,document_root=settings.MEDIA_ROOT)

When I added +static(settings.MEDIA_URL ~ before ,my app worked well. So,I didn't know how I can fix this.

Now I am making Serializer when users logged in my app.

In settings.py,I wrote

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

1 Answer 1

1

Probably it should be like that after urlpatterns:

from django.contrib.staticfiles.urls import staticfiles_urlpatterns

if settings.DEBUG == True:
    urlpatterns += staticfiles_urlpatterns()
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Sign up to request clarification or add additional context in comments.

5 Comments

@user7523656 can you share your related settings?
Is it meaning settings.py?Which part did u think?
@user7523656 I have just noticed that you are not using include for admin urls. Can you please try it first include(admin.site.urls)?
@user7523656 settings related to MEDIA_URL and MEDIA_ROOT
@user7523656 I think it is ok and the problem is not related with code you have provided.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.