Include CSS and Javascript in my django template [duplicate]

First, create staticfiles folder. Inside that folder create css, js, and img folder. settings.py import os PROJECT_DIR = os.path.dirname(__file__) DATABASES = { ‘default’: { ‘ENGINE’: ‘django.db.backends.sqlite3’, ‘NAME’: os.path.join(PROJECT_DIR, ‘myweblabdev.sqlite’), ‘USER’: ”, ‘PASSWORD’: ”, ‘HOST’: ”, ‘PORT’: ”, } } MEDIA_ROOT = os.path.join(PROJECT_DIR, ‘media’) MEDIA_URL = ‘/media/’ STATIC_ROOT = os.path.join(PROJECT_DIR, ‘static’) STATIC_URL = ‘/static/’ STATICFILES_DIRS = … Read more

Django Left Outer Join

First of all, there is no a way (atm Django 1.9.7) to have a representation with Django’s ORM of the raw query you posted, exactly as you want; however, you can get the same desired result with something like: >>> Topic.objects.annotate( f=Case( When( record__user=johnny, then=F(‘record__value’) ), output_field=IntegerField() ) ).order_by( ‘id’, ‘name’, ‘f’ ).distinct( ‘id’, ‘name’ … Read more

How to get the url path of a view function in django

You need reverse. from django.urls import reverse reverse(‘app1.view.view1’) If you want to find out URL and redirect to it, use redirect from django.urls import redirect redirect(‘app1.view.view1’) If want to go further and not to hardcode your view names either, you can name your URL patterns and use these names instead.

How to get logged in user’s uid from session in Django?

In case anyone wants to actually extract a user ID from an actual Session object (for whatever reason – I did!), here’s how: from django.contrib.sessions.models import Session from django.contrib.auth.models import User session_key = ‘8cae76c505f15432b48c8292a7dd0e54’ session = Session.objects.get(session_key=session_key) session_data = session.get_decoded() print session_data uid = session_data.get(‘_auth_user_id’) user = User.objects.get(id=uid) Credit should go to Scott Barnham

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)