Herramientas de usuario

Herramientas del sitio


wiki2:python:medium_django

Diferencias

Muestra las diferencias entre dos versiones de la página.

Enlace a la vista de comparación

Ambos lados, revisión anterior Revisión previa
Próxima revisión
Revisión previa
wiki2:python:medium_django [2018/11/09 10:20]
alfred [Django hows]
wiki2:python:medium_django [2020/05/09 09:25] (actual)
Línea 6: Línea 6:
 <​code>​ <​code>​
 DJANGO_SETTINGS_MODULE = coopolis_backoffice.settings.alfred DJANGO_SETTINGS_MODULE = coopolis_backoffice.settings.alfred
 +</​code>​
 +
 +==== Loggear las peticiones a DB ====
 +En las settings:
 +<​code>​
 +LOGGING = {
 +    '​version':​ 1,
 +    '​disable_existing_loggers':​ False,
 +    '​handlers':​ {
 +        '​console':​ {
 +            '​class':​ '​logging.StreamHandler',​
 +        },
 +    },
 +    '​loggers':​ {
 +        '​django.db.backends':​ {
 +            '​handlers':​ ['​console'​],​
 +            '​level':​ '​DEBUG',​
 +        },
 +    },
 +}
 +
 </​code>​ </​code>​
 ==== How Django manages Url's? ==== ==== How Django manages Url's? ====
Línea 118: Línea 139:
  
 Namespaced URLs are specified using the ':'​ operator. For example, the main index page of the admin application is referenced using '​admin:​index'​. This indicates a namespace of '​admin',​ and a named URL of '​index'​. Namespaces can also be nested. The named URL '​sports:​polls:​index'​ would look for a pattern named '​index'​ in the namespace '​polls'​ that is itself defined within the top-level namespace '​sports'​. Namespaced URLs are specified using the ':'​ operator. For example, the main index page of the admin application is referenced using '​admin:​index'​. This indicates a namespace of '​admin',​ and a named URL of '​index'​. Namespaces can also be nested. The named URL '​sports:​polls:​index'​ would look for a pattern named '​index'​ in the namespace '​polls'​ that is itself defined within the top-level namespace '​sports'​.
 +
 +==== Dynamic fields ====
 +For example in urls:
 +<​code>​
 +urlpatterns = [
 +    path('',​ TemplateView.as_view(
 +        template_name="​fok/​home.html",​
 +        extra_context={
 +            # The lambda makes this expression to be executed each call of home (because of the admin updates)
 +            '​campaigns':​ lambda: Campaign.objects.filter(visible=True).order_by('​-created_at'​)
 +        }
 +    ), name='​home'​),​
 +...
 +</​code>​
  
 ===== Questions ===== ===== Questions =====
wiki2/python/medium_django.1541758846.txt.gz · Última modificación: 2020/05/09 09:24 (editor externo)