Why does DEBUG=False setting make my django Static Files Access fail?

In urls.py I added this line:

from django.views.static import serve 

add those two urls in urlpatterns:

url(r'^media/(?P<path>.*)$', serve,{'document_root': settings.MEDIA_ROOT}), 
url(r'^static/(?P<path>.*)$', serve,{'document_root': settings.STATIC_ROOT}), 

and both static and media files were accesible when DEBUG=FALSE.
Hope it helps 🙂

Django Mysql Distinct

.distinct() is the tool, but here’s the syntax I had to use :

Model.objects.values_list('name', flat=True).distinct()

This way you only get a list [A,B,C,D] of values, not the objects themseleves.

Pek zarif olmasada aşağıdaki de kullanılır.

# Fetch all rows to limit num of queries
all_rows = MyModel.objects.all()

# Query against the full list to return a list of objects
item_list = [all_rows.filter(myfield=item['myfield']).last() for item in MyModel.objects.values('myfield').distinct()]

Django Multi Language

Rosetta paketi yüklenecek.

pip install django-rosetta

urls.py :

if 'rosetta' in settings.INSTALLED_APPS:
    urlpatterns += [
        url(r'^rosetta/', include('rosetta.urls'))

settings.py :


from django.utils.translation import gettext_lazy as _

('en', _('English')),
('tr', _('Turkish')),
('es', _('Spanish')),
    os.path.join(BASE_DIR, 'locale/'),
TIME_ZONE = 'Europe/Istanbul'
USE_I18N = True
USE_L10N = True
USE_TZ = False