Derniers messages sur Zeste de Savoirhttps://zestedesavoir.com/forums/2024-02-28T09:48:22+01:00Les derniers messages parus sur le forum de Zeste de Savoir.A partir d'un clique : trier des données déjà affichées dans le désordre, puis les mettre à jour, message #2541612024-02-28T09:48:22+01:00entwanne/@entwannehttps://zestedesavoir.com/forums/sujet/17352/a-partir-dun-clique-trier-des-donnees-deja-affichees-dans-le-desordre-puis-les-mettre-a-jour/?page=1#p254161<p>Salut,</p>
<p>Est-ce que tu vois bien les requêtes HTTP survenir lorsque tu utilises tes <code><select></code> ? Est-ce qu’elles réussissent ?</p>
<p>Si oui tu pourrais afficher clairement ce qu’elles contiennent pour voir si cela correspond bien au format attendu.</p>
<p>Si non, quelle erreur obtiens-tu ?</p>A partir d'un clique : trier des données déjà affichées dans le désordre, puis les mettre à jour, message #2541552024-02-28T06:56:26+01:00DelphineGillain/@DelphineGillainhttps://zestedesavoir.com/forums/sujet/17352/a-partir-dun-clique-trier-des-donnees-deja-affichees-dans-le-desordre-puis-les-mettre-a-jour/?page=1#p254155<p>Bonjour,</p>
<p>Je bloque depuis plusieurs jours… S’il vous plaît, aidez-moi à comprendre l’origine de mon problème! Il y a vraisemblablement quelque chose que je ne comprends pas bien puisque l’exécution de mon code ne fonctionne pas : lorsque je clique sur une des options de mon sélect, je veux que la liste des livres de mon catalogue soit triée de A à Z ou du plus petit au plus grand, ou bien de Z à A ou du plus grand au plus petit (selon l’option sélectionnée).</p>
<p>Actuellement, je soupçonne la view de mon application de ne pas être correctement intégrée dans celle de mon projet…</p>
<p>Ci-après, voici le contexte d’exécution :</p>
<p>Je débute avec Django. J’ai créé une application nommée "books" qui se rattache à un projet "sgbj". Le template catalog.html de mon application est appelée par le template index.html de mon projet "sgbj". Donc l’url d’affichage de mon application "books" est la même que celle utilisée par mon projet "sgbj" :</p>
<p>Mon ficher urls.py du projet "sgbj":</p>
<div class="hljs-code-div hljs-code-py"><div class="hljs-line-numbers"><span data-count="1"></span><span data-count="2"></span><span data-count="3"></span><span data-count="4"></span><span data-count="5"></span><span data-count="6"></span><span data-count="7"></span><span data-count="8"></span><span data-count="9"></span><span data-count="10"></span></div><pre><code class="hljs language-py"><span class="hljs-keyword">from</span> django.contrib <span class="hljs-keyword">import</span> admin
<span class="hljs-keyword">from</span> django.urls <span class="hljs-keyword">import</span> path, include
<span class="hljs-keyword">from</span> books <span class="hljs-keyword">import</span> views <span class="hljs-keyword">as</span> books_views
<span class="hljs-keyword">from</span> . <span class="hljs-keyword">import</span> views <span class="hljs-keyword">as</span> project_views
urlpatterns = [
path(<span class="hljs-string">'admin/'</span>, admin.site.urls),
path(<span class="hljs-string">''</span>, books_views.catalog_view, name=<span class="hljs-string">'index'</span>),
path(<span class="hljs-string">'contact/'</span>, project_views.contact_view, name=<span class="hljs-string">'contact'</span>),
path(<span class="hljs-string">'publications/'</span>, include(<span class="hljs-string">'articles.urls'</span>), name=<span class="hljs-string">'articles'</span>),
]
</code></pre></div>
<p>Le fichier views.py du projet "sgbj" :</p>
<div class="hljs-code-div hljs-code-py"><div class="hljs-line-numbers"><span data-count="1"></span><span data-count="2"></span><span data-count="3"></span><span data-count="4"></span><span data-count="5"></span><span data-count="6"></span></div><pre><code class="hljs language-py"><span class="hljs-keyword">from</span> django.shortcuts <span class="hljs-keyword">import</span> render
<span class="hljs-keyword">from</span> books.views <span class="hljs-keyword">import</span> catalog_view <span class="hljs-keyword">as</span> books_catalog_view
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">index_view</span>(<span class="hljs-params">request</span>):</span>
catalog_context = books_catalog_view(request)
books = catalog_context.get(<span class="hljs-string">'catalog'</span>)
<span class="hljs-keyword">return</span> render(request, <span class="hljs-string">'index.html'</span>, {<span class="hljs-string">'catalog'</span>: books})
</code></pre></div>
<p>Le template index.html du projet "sgbj" :</p>
<div class="hljs-code-div hljs-code-html"><div class="hljs-line-numbers"><span data-count="1"></span><span data-count="2"></span><span data-count="3"></span><span data-count="4"></span><span data-count="5"></span><span data-count="6"></span><span data-count="7"></span><span data-count="8"></span><span data-count="9"></span><span data-count="10"></span><span data-count="11"></span><span data-count="12"></span></div><pre><code class="hljs language-html">{% extends 'template_base.html' %}
{% block title %}Home_page{% endblock %}
{% block content %}
{% block catalog_content %}
<span class="hljs-tag"><<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"catalog_content"</span>></span>
{% include 'catalog.html' %}
<span class="hljs-tag"></<span class="hljs-name">div</span>></span>
{% endblock %}
{% block sort_books %}
{% endblock %}
{% endblock %}
</code></pre></div>
<p>Le template catalog.html de l’application "books":</p>
<div class="hljs-code-div hljs-code-html"><div class="hljs-line-numbers"><span data-count="1"></span><span data-count="2"></span><span data-count="3"></span><span data-count="4"></span><span data-count="5"></span><span data-count="6"></span><span data-count="7"></span><span data-count="8"></span><span data-count="9"></span><span data-count="10"></span><span data-count="11"></span><span data-count="12"></span><span data-count="13"></span><span data-count="14"></span><span data-count="15"></span><span data-count="16"></span><span data-count="17"></span><span data-count="18"></span><span data-count="19"></span><span data-count="20"></span><span data-count="21"></span><span data-count="22"></span><span data-count="23"></span><span data-count="24"></span><span data-count="25"></span><span data-count="26"></span><span data-count="27"></span><span data-count="28"></span><span data-count="29"></span><span data-count="30"></span><span data-count="31"></span><span data-count="32"></span><span data-count="33"></span><span data-count="34"></span><span data-count="35"></span></div><pre><code class="hljs language-html">{% extends 'template_base.html' %}
{% block title %}Catalog_page{% endblock %}
{% block content %}
{% block sort_books %}
<span class="hljs-tag"><<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"sort_books"</span>></span>
Tri par :
<span class="hljs-tag"><<span class="hljs-name">select</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"sort_lastname"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"select_books sort_lastname"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"lastname"</span>></span>
<span class="hljs-tag"><<span class="hljs-name">option</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"sort_lastname_author"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"sort_label"</span> <span class="hljs-attr">disabled</span> <span class="hljs-attr">selected</span> <span class="hljs-attr">hidden</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"no_specific"</span>></span>auteur <span class="hljs-tag"></<span class="hljs-name">option</span>></span>
<span class="hljs-tag"><<span class="hljs-name">option</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"sort_lastname_AZ"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"display_asc option_transparent"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"asc"</span>></span>A ... Z<span class="hljs-tag"></<span class="hljs-name">option</span>></span>
<span class="hljs-tag"><<span class="hljs-name">option</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"sort_lastname_ZA"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"display_desc option_transparent"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"desc"</span>></span>Z ... A<span class="hljs-tag"></<span class="hljs-name">option</span>></span>
<span class="hljs-tag"></<span class="hljs-name">select</span>></span>
<span class="hljs-tag"><<span class="hljs-name">select</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"sort_title"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"select_books"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"titre"</span>></span>
<span class="hljs-tag"><<span class="hljs-name">option</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"sort_title_title"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"sort_label"</span> <span class="hljs-attr">disabled</span> <span class="hljs-attr">selected</span> <span class="hljs-attr">hidden</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"no_specific"</span>></span>titre <span class="hljs-tag"></<span class="hljs-name">option</span>></span>
<span class="hljs-tag"><<span class="hljs-name">option</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"sort_title_AZ"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"display_asc option_transparent"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"asc"</span>></span>A ... Z<span class="hljs-tag"></<span class="hljs-name">option</span>></span>
<span class="hljs-tag"><<span class="hljs-name">option</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"sort_title_ZA"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"display_desc option_transparent"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"desc"</span>></span>Z ... A<span class="hljs-tag"></<span class="hljs-name">option</span>></span>
<span class="hljs-tag"></<span class="hljs-name">select</span>></span>
<span class="hljs-tag"><<span class="hljs-name">select</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"sort_date"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"select_books"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"date"</span>></span>
<span class="hljs-tag"><<span class="hljs-name">option</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"sort_date_date"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"sort_label"</span> <span class="hljs-attr">disabled</span> <span class="hljs-attr">selected</span> <span class="hljs-attr">hidden</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"no_specific"</span>></span>date <span class="hljs-tag"></<span class="hljs-name">option</span>></span>
<span class="hljs-tag"><<span class="hljs-name">option</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"sort_date_-+"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"display_asc option_transparent"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"asc"</span>></span>- ... +<span class="hljs-tag"></<span class="hljs-name">option</span>></span>
<span class="hljs-tag"><<span class="hljs-name">option</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"sort_date_+-"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"display_desc option_transparent"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"desc"</span>></span>+ ... -<span class="hljs-tag"></<span class="hljs-name">option</span>></span>
<span class="hljs-tag"></<span class="hljs-name">select</span>></span>
<span class="hljs-tag"></<span class="hljs-name">div</span>></span>
{% endblock %}
{% block catalog_title %}
<span class="hljs-tag"><<span class="hljs-name">h1</span>></span>Ma bibliothèque<span class="hljs-tag"></<span class="hljs-name">h1</span>></span>
{% endblock %}
{% for book in catalog %}
<span class="hljs-tag"><<span class="hljs-name">p</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"catalog"</span>></span>
<span class="hljs-tag"><<span class="hljs-name">span</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"lastname"</span>></span>{{ book.lastname }}<span class="hljs-tag"></<span class="hljs-name">span</span>></span>
<span class="hljs-tag"><<span class="hljs-name">span</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"firstname"</span>></span>{{ book.firstname }}<span class="hljs-tag"></<span class="hljs-name">span</span>></span>
<span class="hljs-tag"><<span class="hljs-name">span</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"title"</span>></span><span class="hljs-tag"><<span class="hljs-name">b</span>></span>{{ book.title }}<span class="hljs-tag"></<span class="hljs-name">b</span>></span><span class="hljs-tag"></<span class="hljs-name">span</span>></span>
<span class="hljs-tag"><<span class="hljs-name">span</span>></span>ISBN : <span class="hljs-tag"><<span class="hljs-name">span</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"isbn"</span>></span>{{ book.isbn }}<span class="hljs-tag"></<span class="hljs-name">span</span>></span>
<span class="hljs-tag"></<span class="hljs-name">p</span>></span>
{% endfor %}
{% endblock %}
</code></pre></div>
<p>La vue views.py de l’application "books" :</p>
<div class="hljs-code-div hljs-code-py"><div class="hljs-line-numbers"><span data-count="1"></span><span data-count="2"></span><span data-count="3"></span><span data-count="4"></span><span data-count="5"></span><span data-count="6"></span><span data-count="7"></span><span data-count="8"></span><span data-count="9"></span><span data-count="10"></span><span data-count="11"></span><span data-count="12"></span><span data-count="13"></span><span data-count="14"></span><span data-count="15"></span><span data-count="16"></span><span data-count="17"></span><span data-count="18"></span><span data-count="19"></span><span data-count="20"></span><span data-count="21"></span><span data-count="22"></span><span data-count="23"></span><span data-count="24"></span><span data-count="25"></span><span data-count="26"></span><span data-count="27"></span><span data-count="28"></span><span data-count="29"></span><span data-count="30"></span></div><pre><code class="hljs language-py"><span class="hljs-keyword">from</span> django.shortcuts <span class="hljs-keyword">import</span> render
<span class="hljs-keyword">from</span> django.http <span class="hljs-keyword">import</span> JsonResponse
<span class="hljs-keyword">from</span> django.db.models.functions <span class="hljs-keyword">import</span> Lower
<span class="hljs-keyword">from</span> .models <span class="hljs-keyword">import</span> Book
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">catalog_view</span>(<span class="hljs-params">request</span>):</span>
books = Book.objects.<span class="hljs-built_in">all</span>()
<span class="hljs-keyword">return</span> render(request, <span class="hljs-string">'books/catalog.html'</span>, {<span class="hljs-string">'catalog'</span>: books})
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">sort_books_view</span>(<span class="hljs-params">request</span>):</span>
<span class="hljs-keyword">if</span> request.is_ajax() <span class="hljs-keyword">and</span> <span class="hljs-string">'selected_option'</span> <span class="hljs-keyword">in</span> request.GET:
selected_column_option = request.GET.get(<span class="hljs-string">'selected_option'</span>)
column_mapping = {
<span class="hljs-string">'sort_lastname_AZ'</span>: <span class="hljs-string">'lastname'</span>,
<span class="hljs-string">'sort_lastname_ZA'</span>: <span class="hljs-string">'-lastname'</span>,
<span class="hljs-string">'sort_firstname_AZ'</span>: <span class="hljs-string">'firstname'</span>,
<span class="hljs-string">'sort_firstname_ZA'</span>: <span class="hljs-string">'-firstname'</span>,
<span class="hljs-string">'sort_title_AZ'</span>: <span class="hljs-string">'title'</span>,
<span class="hljs-string">'sort_title_ZA'</span>: <span class="hljs-string">'-title'</span>,
<span class="hljs-string">'sort_date_-+'</span>: Lower(<span class="hljs-string">'date'</span>),
<span class="hljs-string">'sort_date_+-'</span>: Lower(<span class="hljs-string">'-date'</span>),
}
<span class="hljs-keyword">if</span> selected_column_option <span class="hljs-keyword">in</span> column_mapping:
sort_column = column_mapping[selected_column_option]
books = Book.objects.<span class="hljs-built_in">all</span>().order_by(sort_column)
sorted_books = [{<span class="hljs-string">'lastname'</span>: book.lastname, <span class="hljs-string">'firstname'</span>: book.firstname, <span class="hljs-string">'title'</span>: book.title, <span class="hljs-string">'isbn'</span>: book.isbn} <span class="hljs-keyword">for</span> book <span class="hljs-keyword">in</span> books]
<span class="hljs-keyword">return</span> JsonResponse(sorted_books, safe=<span class="hljs-literal">False</span>)
<span class="hljs-keyword">else</span>:
<span class="hljs-keyword">return</span> JsonResponse({<span class="hljs-string">'error'</span>: <span class="hljs-string">'Option de tri non valide.'</span>})
<span class="hljs-keyword">else</span>:
<span class="hljs-keyword">return</span> JsonResponse({<span class="hljs-string">'error'</span>: <span class="hljs-string">'Cette vue ne peut être appelée que via AJAX.'</span>})
</code></pre></div>
<p>Mon script selector_books.js de l’application "books" (voir les lignes 46 à 82):</p>
<div class="hljs-code-div hljs-code-js"><div class="hljs-line-numbers"><span data-count="1"></span><span data-count="2"></span><span data-count="3"></span><span data-count="4"></span><span data-count="5"></span><span data-count="6"></span><span data-count="7"></span><span data-count="8"></span><span data-count="9"></span><span data-count="10"></span><span data-count="11"></span><span data-count="12"></span><span data-count="13"></span><span data-count="14"></span><span data-count="15"></span><span data-count="16"></span><span data-count="17"></span><span data-count="18"></span><span data-count="19"></span><span data-count="20"></span><span data-count="21"></span><span data-count="22"></span><span data-count="23"></span><span data-count="24"></span><span data-count="25"></span><span data-count="26"></span><span data-count="27"></span><span data-count="28"></span><span data-count="29"></span><span data-count="30"></span><span data-count="31"></span><span data-count="32"></span><span data-count="33"></span><span data-count="34"></span><span data-count="35"></span><span data-count="36"></span><span data-count="37"></span><span data-count="38"></span><span data-count="39"></span><span data-count="40"></span><span data-count="41"></span><span data-count="42"></span><span data-count="43"></span><span data-count="44"></span><span data-count="45"></span><span data-count="46"></span><span data-count="47"></span><span data-count="48"></span><span data-count="49"></span><span data-count="50"></span><span data-count="51"></span><span data-count="52"></span><span data-count="53"></span><span data-count="54"></span><span data-count="55"></span><span data-count="56"></span><span data-count="57"></span><span data-count="58"></span><span data-count="59"></span><span data-count="60"></span><span data-count="61"></span><span data-count="62"></span><span data-count="63"></span><span data-count="64"></span><span data-count="65"></span><span data-count="66"></span><span data-count="67"></span><span data-count="68"></span><span data-count="69"></span><span data-count="70"></span><span data-count="71"></span><span data-count="72"></span><span data-count="73"></span><span data-count="74"></span><span data-count="75"></span><span data-count="76"></span><span data-count="77"></span><span data-count="78"></span><span data-count="79"></span><span data-count="80"></span><span data-count="81"></span><span data-count="82"></span><span data-count="83"></span></div><pre><code class="hljs language-js"><span class="hljs-built_in">document</span>.addEventListener(<span class="hljs-string">'DOMContentLoaded'</span>, <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{
<span class="hljs-keyword">var</span> selectElements = <span class="hljs-built_in">document</span>.querySelectorAll(<span class="hljs-string">'#sort_lastname, #sort_firstname, #sort_title, #sort_date'</span>);
<span class="hljs-keyword">var</span> defaultLabelOptions = {};
selectElements.forEach(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">selectElement</span>) </span>{
<span class="hljs-keyword">var</span> defaultLabelOption = selectElement.querySelector(<span class="hljs-string">'option'</span>);
defaultLabelOptions[selectElement.id] = defaultLabelOption.textContent;
defaultLabelOption.style.display = <span class="hljs-string">'none'</span>;
selectElement.addEventListener(<span class="hljs-string">'change'</span>, <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{
<span class="hljs-keyword">var</span> selectedOption = <span class="hljs-built_in">this</span>.options[<span class="hljs-built_in">this</span>.selectedIndex];
<span class="hljs-keyword">var</span> optionClass = selectedOption.getAttribute(<span class="hljs-string">'class'</span>);
<span class="hljs-keyword">var</span> optionText = selectedOption.textContent;
selectElements.forEach(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">otherSelect</span>) </span>{
<span class="hljs-keyword">if</span> (otherSelect !== selectElement) {
<span class="hljs-keyword">var</span> defaultOption = otherSelect.querySelector(<span class="hljs-string">'option[value="no_specific"]'</span>);
defaultOption.style.display = <span class="hljs-string">''</span>;
defaultOption.selected = <span class="hljs-literal">true</span>;
otherSelect.querySelectorAll(<span class="hljs-string">'option'</span>).forEach(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">option</span>) </span>{
option.style.display = <span class="hljs-string">''</span>;
});
}
});
<span class="hljs-comment">// Afficher toutes les options</span>
<span class="hljs-keyword">var</span> options = selectElement.querySelectorAll(<span class="hljs-string">'option'</span>);
options.forEach(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">option</span>) </span>{
option.style.display = <span class="hljs-string">''</span>;
});
<span class="hljs-comment">// Cacher l'option sélectionnée</span>
selectedOption.style.display = <span class="hljs-string">'none'</span>;
<span class="hljs-keyword">if</span> (optionClass === <span class="hljs-string">'sort_label'</span> || (optionText !== <span class="hljs-string">'auteur A ... Z'</span> && optionText !== <span class="hljs-string">'auteur Z ... A'</span> && optionText !== <span class="hljs-string">'titre A ... Z'</span> && optionText !== <span class="hljs-string">'titre Z ... A'</span> && optionText !== <span class="hljs-string">'date - ... +'</span> && optionText !== <span class="hljs-string">'date + ... -'</span>)) {
selectedOption.textContent = defaultLabelOptions[selectElement.id] + optionText;
}
<span class="hljs-comment">// Masquer les options appropriées sans masquer l'élément sélectionné</span>
<span class="hljs-keyword">if</span> (optionClass === <span class="hljs-string">'display_asc'</span>) {
<span class="hljs-keyword">var</span> descOptions = selectElement.parentNode.querySelectorAll(<span class="hljs-string">'.display_desc'</span>);
descOptions.forEach(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">option</span>) </span>{
option.style.display = <span class="hljs-string">''</span>;
});
} <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (optionClass === <span class="hljs-string">'display_desc'</span>) {
<span class="hljs-keyword">var</span> ascOptions = selectElement.parentNode.querySelectorAll(<span class="hljs-string">'.display_asc'</span>);
ascOptions.forEach(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">option</span>) </span>{
option.style.display = <span class="hljs-string">''</span>;
});
}
});
});
$(<span class="hljs-string">'#sort_lastname, #sort_firstname, #sort_title, #sort_date'</span>).on(<span class="hljs-string">'change'</span>, <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{
<span class="hljs-keyword">var</span> selectedOption = $(<span class="hljs-built_in">this</span>).val();
<span class="hljs-keyword">if</span> (selectedOption === <span class="hljs-string">"AZ"</span> || selectedOption === <span class="hljs-string">"-+"</span> || selectedOption === <span class="hljs-string">"ZA"</span> || selectedOption === <span class="hljs-string">"+-"</span> ) {
<span class="hljs-keyword">var</span> dataToSend = {};
<span class="hljs-keyword">var</span> selectedColumn = <span class="hljs-string">''</span>;
<span class="hljs-keyword">if</span> ($(<span class="hljs-built_in">this</span>).attr(<span class="hljs-string">'id'</span>) === <span class="hljs-string">'sort_lastname'</span>) {
selectedColumn = <span class="hljs-string">'lastname'</span>;
dataToSend[<span class="hljs-string">'selected_lastname_option'</span>] = <span class="hljs-string">'sort_'</span> + selectedColumn + <span class="hljs-string">'_'</span> + selectedOption.toUpperCase();
dataToSend[<span class="hljs-string">'selected_firstname_option'</span>] = <span class="hljs-string">'sort_firstname_'</span> + selectedOption.toUpperCase();
} <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> ($(<span class="hljs-built_in">this</span>).attr(<span class="hljs-string">'id'</span>) === <span class="hljs-string">'sort_firstname'</span>) {
selectedColumn = <span class="hljs-string">'firstname'</span>;
dataToSend[<span class="hljs-string">'selected_firstname_option'</span>] = <span class="hljs-string">'sort_'</span> + selectedColumn + <span class="hljs-string">'_'</span> + selectedOption.toUpperCase();
dataToSend[<span class="hljs-string">'selected_lastname_option'</span>] = <span class="hljs-string">'sort_lastname_'</span> + selectedOption.toUpperCase();
} <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> ($(<span class="hljs-built_in">this</span>).attr(<span class="hljs-string">'id'</span>) === <span class="hljs-string">'sort_title'</span>) {
selectedColumn = <span class="hljs-string">'title'</span>;
} <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> ($(<span class="hljs-built_in">this</span>).attr(<span class="hljs-string">'id'</span>) === <span class="hljs-string">'sort_date'</span>) {
selectedColumn = <span class="hljs-string">'date'</span>;
}
$.ajax({
<span class="hljs-attr">url</span>: <span class="hljs-string">''</span>,
<span class="hljs-attr">data</span>: dataToSend,
<span class="hljs-attr">dataType</span>: <span class="hljs-string">'json'</span>,
<span class="hljs-attr">success</span>: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">data</span>) </span>{
updateIndexData(data, selectedColumn);
}
});
}
});
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">updateIndexData</span>(<span class="hljs-params">data, selectedColumn</span>) </span>{
$(<span class="hljs-string">'#catalog_content .catalog p'</span>).each(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">index</span>) </span>{
$(<span class="hljs-built_in">this</span>).find(<span class="hljs-string">'.'</span> + selectedColumn).text(data[index][selectedColumn]);
$(<span class="hljs-built_in">this</span>).find(<span class="hljs-string">'.isbn'</span>).text(<span class="hljs-string">'ISBN : '</span> + data[index].isbn);
});
}
});
</code></pre></div>
<p>L’affichage web en local fonctionnait bien avant que j’essaye de trier les données par ordre croissant/décroissant. J’espère que vous voudrez bien m’aider à identifier l’origine de la non exécution de mon code!</p>Utiliser l'authentification d'un site wordpress pour se connecter automatiquement à un site Django, message #2524842023-10-17T13:40:32+02:00entwanne/@entwannehttps://zestedesavoir.com/forums/sujet/17168/utiliser-lauthentification-dun-site-wordpress-pour-se-connecter-automatiquement-a-un-site-django/?page=1#p252484<p>Salut,</p>
<p>Je n’ai pas directement la réponse à ta question, mais peut-être quelques questions complémentaires qui pourront permettre de t’orienter.</p>
<ul>
<li>Est-ce que les deux sites seront hébergés sur le même domaine ?</li>
<li>Est-ce que tes deux applications partagent une base de données commune ?</li>
<li>Comment communiquent les deux applications, comment se fait le passage de l’une à l’autre ?</li>
</ul>
<p>J’ai du mal à comprendre la première réponse stackoverflow (j’ai l’impression que ça parle d’un modèle qui irait lire la base de données de l’app wordpress mais je ne suis pas sûr), en revanche les deux solutions parlent d’un <a href="https://wordpress.org/plugins/jwt-authentication-for-wp-rest-api/">plugin JWT</a> à mettre en place côté Wordpress qui permettrait d’exporter un jeton de connexion.</p>
<p>Côté Django tu as par exemple <a href="https://django-rest-framework-simplejwt.readthedocs.io/en/latest/">ce paquet</a> que tu pourrais mettre en place pour authentifier un utilisateur à l’aide d’un jeton JWT.</p>Utiliser l'authentification d'un site wordpress pour se connecter automatiquement à un site Django, message #2524382023-10-11T19:19:54+02:00LudoBike/@LudoBikehttps://zestedesavoir.com/forums/sujet/17168/utiliser-lauthentification-dun-site-wordpress-pour-se-connecter-automatiquement-a-un-site-django/?page=1#p252438<p>Salut !</p>
<p>Voici ma situation actuelle : je code un site en django pour un client qui a un site de commerce réalisé avec Wordpress. Le client voudrait que quand un utilisateur connecté sur le site Wordpress ouvre le site Django, il soit déjà connecté. </p>
<p>En cherchant sur internet, j’ai trouvé <a href="https://stackoverflow.com/questions/45915936/single-sign-on-between-wordpress-and-django">ce post stack overflow</a> qui a l’air de parfaitement correspondre à mon problème mais je ne comprends pas comment mettre en œuvre la réponse apportée. En particulier, je ne vois pas ce que je dois setup dans mon projet Django pour que l’authentification fonctionne.</p>
<p>Si vous avez des pistes sur comment faire ça je suis vraiment preneur.</p>
<p>En vous remerciant d’avance pour l’aide apportée !</p>
<p><strong>NB:</strong> Pour l’instant dans mon projet Django l’authentification est entièrement géré par le module <code>django.contrib.auth</code></p>déployer une application web django, message #2505532023-05-26T12:04:48+02:001e49ba0eba/@1e49ba0ebahttps://zestedesavoir.com/forums/sujet/16972/deployer-une-application-web-django/?page=1#p250553<p>ok, j’ai trouvé l’erreur : le <code>manage.py migrate</code> n’avait pas migré les differentes apps. J’ai du faire <code>manage.py migrate add</code> pour chacune des applications séparément.</p>
<p>Donc erreur crsf semble résolue et j’arrive à me connecter au pages nécessitant une lecture dans la bdd.</p>
<p> Restent comme problèmes :</p>
<ul>
<li>l’activation de lets-encrypt: en suivant le <a href="https://certbot.eff.org/instructions?ws=nginx&os=debianbuster">tutoriel officiel</a>, je suis bloqué à l’étape <code>sudo snap install core</code> qui me retourne : <code>error: cannot install "core": persistent network error: Post "https://api.snapcraft.io/v2/snaps/refresh": dial tcp 185.125.188.54:443: connect: network is unreachable</code></li>
<li>les url des différentes pages retournent une 404 si je ne mets pas le <code>\</code> à la fin. Bon, c’est assez secondaire ça.</li>
</ul>déployer une application web django, message #2505512023-05-26T09:34:24+02:001e49ba0eba/@1e49ba0ebahttps://zestedesavoir.com/forums/sujet/16972/deployer-une-application-web-django/?page=1#p250551<div class="hljs-code-div hljs-code-Python"><div class="hljs-line-numbers"><span data-count="1"></span><span data-count="2"></span><span data-count="3"></span><span data-count="4"></span><span data-count="5"></span></div><pre><code class="hljs language-Python"><span class="hljs-comment"># settings.__init__.py:</span>
<span class="hljs-comment">#from .dev import *</span>
<span class="hljs-keyword">from</span> .prod <span class="hljs-keyword">import</span> *
<span class="hljs-keyword">from</span> .common <span class="hljs-keyword">import</span> *
</code></pre></div>
<p>settings.prod.py c’est celui que j’ai posté plus haut dans le topic.</p>
<div class="hljs-code-div hljs-code-Python"><div class="hljs-line-numbers"><span data-count="1"></span><span data-count="2"></span><span data-count="3"></span><span data-count="4"></span><span data-count="5"></span><span data-count="6"></span><span data-count="7"></span><span data-count="8"></span><span data-count="9"></span><span data-count="10"></span><span data-count="11"></span><span data-count="12"></span><span data-count="13"></span><span data-count="14"></span><span data-count="15"></span><span data-count="16"></span><span data-count="17"></span><span data-count="18"></span><span data-count="19"></span><span data-count="20"></span><span data-count="21"></span><span data-count="22"></span><span data-count="23"></span><span data-count="24"></span><span data-count="25"></span><span data-count="26"></span><span data-count="27"></span><span data-count="28"></span><span data-count="29"></span><span data-count="30"></span><span data-count="31"></span><span data-count="32"></span><span data-count="33"></span><span data-count="34"></span><span data-count="35"></span><span data-count="36"></span><span data-count="37"></span><span data-count="38"></span><span data-count="39"></span><span data-count="40"></span><span data-count="41"></span><span data-count="42"></span><span data-count="43"></span><span data-count="44"></span><span data-count="45"></span><span data-count="46"></span><span data-count="47"></span><span data-count="48"></span><span data-count="49"></span><span data-count="50"></span><span data-count="51"></span><span data-count="52"></span><span data-count="53"></span><span data-count="54"></span><span data-count="55"></span><span data-count="56"></span><span data-count="57"></span><span data-count="58"></span><span data-count="59"></span><span data-count="60"></span><span data-count="61"></span><span data-count="62"></span><span data-count="63"></span><span data-count="64"></span><span data-count="65"></span><span data-count="66"></span><span data-count="67"></span><span data-count="68"></span><span data-count="69"></span><span data-count="70"></span><span data-count="71"></span><span data-count="72"></span><span data-count="73"></span><span data-count="74"></span><span data-count="75"></span><span data-count="76"></span><span data-count="77"></span><span data-count="78"></span><span data-count="79"></span><span data-count="80"></span><span data-count="81"></span><span data-count="82"></span><span data-count="83"></span><span data-count="84"></span><span data-count="85"></span><span data-count="86"></span><span data-count="87"></span><span data-count="88"></span><span data-count="89"></span><span data-count="90"></span><span data-count="91"></span><span data-count="92"></span><span data-count="93"></span><span data-count="94"></span><span data-count="95"></span><span data-count="96"></span><span data-count="97"></span><span data-count="98"></span><span data-count="99"></span><span data-count="100"></span><span data-count="101"></span><span data-count="102"></span><span data-count="103"></span><span data-count="104"></span><span data-count="105"></span><span data-count="106"></span><span data-count="107"></span><span data-count="108"></span><span data-count="109"></span><span data-count="110"></span><span data-count="111"></span><span data-count="112"></span><span data-count="113"></span><span data-count="114"></span><span data-count="115"></span><span data-count="116"></span><span data-count="117"></span><span data-count="118"></span><span data-count="119"></span><span data-count="120"></span><span data-count="121"></span><span data-count="122"></span><span data-count="123"></span><span data-count="124"></span><span data-count="125"></span><span data-count="126"></span><span data-count="127"></span><span data-count="128"></span><span data-count="129"></span><span data-count="130"></span><span data-count="131"></span></div><pre><code class="hljs language-Python"><span class="hljs-comment"># settings.common.py:</span>
<span class="hljs-keyword">from</span> pathlib <span class="hljs-keyword">import</span> Path
<span class="hljs-keyword">from</span> datetime <span class="hljs-keyword">import</span> datetime
BASE_DIR = Path(__file__).resolve().parent.parent
STATIC_URL = <span class="hljs-string">'static/'</span>
STATIC_ROOT = <span class="hljs-string">'static'</span>
MEDIA_URL = <span class="hljs-string">'medias/'</span> <span class="hljs-comment"># Base url to serve media files</span>
MEDIA_ROOT = <span class="hljs-string">'medias/'</span> <span class="hljs-comment"># Path where media is stored</span>
INSTALLED_APPS = [
<span class="hljs-string">'gunicorn'</span>,
<span class="hljs-string">'configuration.apps.ConfigConfig'</span>,
<span class="hljs-string">'blog.apps.BlogConfig'</span>,
<span class="hljs-string">'blog.templatetags'</span>,
<span class="hljs-string">'comments.apps.CommentsConfig'</span>,
<span class="hljs-string">'django.contrib.admin'</span>,
<span class="hljs-string">'django.contrib.auth'</span>,
<span class="hljs-string">'django.contrib.contenttypes'</span>,
<span class="hljs-string">'django.contrib.sessions'</span>,
<span class="hljs-string">'django.contrib.messages'</span>,
<span class="hljs-string">'django.contrib.staticfiles'</span>,
<span class="hljs-string">'django.contrib.postgres'</span>,
<span class="hljs-string">'django.contrib.humanize'</span>,
<span class="hljs-string">'markdownx'</span>,
<span class="hljs-string">'taggit'</span>,
<span class="hljs-string">'reversion'</span>,
<span class="hljs-string">'dbbackup'</span>,
<span class="hljs-string">'solo'</span>,
]
MIDDLEWARE = [
<span class="hljs-string">'django.middleware.security.SecurityMiddleware'</span>,
<span class="hljs-string">'django.contrib.sessions.middleware.SessionMiddleware'</span>,
<span class="hljs-string">'django.middleware.locale.LocaleMiddleware'</span>,
<span class="hljs-string">'django.middleware.common.CommonMiddleware'</span>,
<span class="hljs-string">'django.middleware.csrf.CsrfViewMiddleware'</span>,
<span class="hljs-string">'django.contrib.auth.middleware.AuthenticationMiddleware'</span>,
<span class="hljs-string">'django.contrib.messages.middleware.MessageMiddleware'</span>,
<span class="hljs-string">'django.middleware.clickjacking.XFrameOptionsMiddleware'</span>,
]
ROOT_URLCONF = <span class="hljs-string">'Website.urls'</span>
TEMPLATES = [
{
<span class="hljs-string">'BACKEND'</span>: <span class="hljs-string">'django.template.backends.django.DjangoTemplates'</span>,
<span class="hljs-string">'DIRS'</span>: [],
<span class="hljs-string">'APP_DIRS'</span>: <span class="hljs-literal">True</span>,
<span class="hljs-string">'OPTIONS'</span>: {
<span class="hljs-string">'context_processors'</span>: [
<span class="hljs-string">'django.template.context_processors.debug'</span>,
<span class="hljs-string">'django.template.context_processors.request'</span>,
<span class="hljs-string">'django.contrib.auth.context_processors.auth'</span>,
<span class="hljs-string">'django.contrib.messages.context_processors.messages'</span>,
],
},
},
]
WSGI_APPLICATION = <span class="hljs-string">'Website.wsgi.application'</span>
AUTH_PASSWORD_VALIDATORS = [
{
<span class="hljs-string">'NAME'</span>: <span class="hljs-string">'django.contrib.auth.password_validation.UserAttributeSimilarityValidator'</span>,
},
{
<span class="hljs-string">'NAME'</span>: <span class="hljs-string">'django.contrib.auth.password_validation.MinimumLengthValidator'</span>,
},
{
<span class="hljs-string">'NAME'</span>: <span class="hljs-string">'django.contrib.auth.password_validation.CommonPasswordValidator'</span>,
},
{
<span class="hljs-string">'NAME'</span>: <span class="hljs-string">'django.contrib.auth.password_validation.NumericPasswordValidator'</span>,
},
]
LANGUAGE_CODE = <span class="hljs-string">'fr-fr'</span>
TIME_ZONE = <span class="hljs-string">'Europe/Paris'</span>
USE_I18N = <span class="hljs-literal">True</span>
USE_TZ = <span class="hljs-literal">True</span>
USE_L10N = <span class="hljs-literal">True</span>
USE_THOUSANDS_SEPARATOR = <span class="hljs-literal">True</span>
DEFAULT_AUTO_FIELD = <span class="hljs-string">'django.db.models.BigAutoField'</span>
TEMPLATE_CONTEXT_PROCESSORS = (
<span class="hljs-string">"django.contrib.auth.context_processors.auth"</span>,
<span class="hljs-string">"django.core.context_processors.debug"</span>,
<span class="hljs-string">"django.core.context_processors.i18n"</span>,
<span class="hljs-string">"django.core.context_processors.media"</span>,
<span class="hljs-string">"django.core.context_processors.static"</span>,
<span class="hljs-string">"django.core.context_processors.tz"</span>,
<span class="hljs-string">"django.contrib.messages.context_processors.messages"</span>,
<span class="hljs-string">"blog.context_processors.views_list"</span>,
)
DEFAULT_FROM_EMAIL = <span class="hljs-string">'no-reply@domaine.fr'</span>
EMAIL_BACKEND = <span class="hljs-string">'django.core.mail.backends.smtp.EmailBackend'</span>
<span class="hljs-comment"># Taggit parameters:</span>
<span class="hljs-comment"># ==================</span>
TAGGIT_CASE_INSENSITIVE = <span class="hljs-literal">True</span>
TAGGIT_STRIP_UNICODE_WHEN_SLUGIFYING = <span class="hljs-literal">True</span>
<span class="hljs-comment"># Django-markdownx parameters:</span>
<span class="hljs-comment"># ============================</span>
MARKDOWNX_MARKDOWN_EXTENSIONS = [
<span class="hljs-string">'markdown.extensions.extra'</span>,
<span class="hljs-string">'markdown.extensions.codehilite'</span>,
<span class="hljs-string">'markdown.extensions.toc'</span>,
<span class="hljs-string">'markdown.extensions.admonition'</span>,
<span class="hljs-string">'markdown_del_ins'</span>,
<span class="hljs-string">'markdown_katex'</span>,
<span class="hljs-string">'mdx_linkify'</span>,
]
MARKDOWNX_MARKDOWNIFY_FUNCTION = <span class="hljs-string">'markdownx.utils.markdownify'</span>
MARKDOWNX_MEDIA_PATH = datetime.now().strftime(<span class="hljs-string">'markdownx/%Y/%m/%d'</span>)
LOGIN_URL = <span class="hljs-string">"/admin/login"</span>
</code></pre></div>déployer une application web django, message #2505492023-05-25T20:34:35+02:00Ge0/@Ge0https://zestedesavoir.com/forums/sujet/16972/deployer-une-application-web-django/?page=1#p250549<p>Salut,</p>
<p>montre-nous la configuration complète de ton projet Django. Quels sont les <em>middlewares</em> actifs, notamment ?</p>déployer une application web django, message #2505472023-05-25T13:48:37+02:001e49ba0eba/@1e49ba0ebahttps://zestedesavoir.com/forums/sujet/16972/deployer-une-application-web-django/?page=1#p250547<p>Ok, j’ai rajouté</p>
<div class="hljs-code-div hljs-code-text"><div class="hljs-line-numbers"><span data-count="1"></span><span data-count="2"></span><span data-count="3"></span><span data-count="4"></span></div><pre><code class="hljs language-text">location / {
proxy_pass http://unix:/tmp/gunicorn.[domaine].sock;
proxy_set_header X-Real-IP $remote_addr; # get real Client IP
}
</code></pre></div>
<p>à la conf de nginx et les requêtes statiques fonctionnent.
Si quelqu’un à une explication sur pourquoi le <code>upstream</code> ne fonctionne pas, ça m’intéresse.</p>
<p>En revanches, les formulaires ne fonctionnent pas. J’ai une erreur</p>
<div class="hljs-code-div hljs-code-text"><div class="hljs-line-numbers"><span data-count="1"></span><span data-count="2"></span><span data-count="3"></span></div><pre><code class="hljs language-text">Interdit (403)
La vérification CSRF a échoué. La requête a été interrompue.
</code></pre></div>
<p>J’ai rajouté <code>CSRF_TRUSTED_ORIGINS=['[domaine].fr']</code> à mon setting.py, mais ça n’as rien changé.</p>déployer une application web django, message #2505452023-05-25T10:42:44+02:001e49ba0eba/@1e49ba0ebahttps://zestedesavoir.com/forums/sujet/16972/deployer-une-application-web-django/?page=1#p250545<p>Je me demande s’il n’y a pas des questions de droit d’accès linux au milieux.</p>
<p>pour le moment j’ai mis</p>
<div class="hljs-code-div hljs-code-text"><pre><code class="hljs language-text">host all all all trust
</code></pre></div>
<p>le temps de résoudre le problème.
Je n’ai plus de message d’erreur dans mes logs en faisant cela, mais je n’arrive toujours pas à me connecter.</p>
<p>voici mon setting.py (enfin la partie qui change en prod)</p>
<div class="hljs-code-div hljs-code-Python"><div class="hljs-line-numbers"><span data-count="1"></span><span data-count="2"></span><span data-count="3"></span><span data-count="4"></span><span data-count="5"></span><span data-count="6"></span><span data-count="7"></span><span data-count="8"></span><span data-count="9"></span><span data-count="10"></span><span data-count="11"></span><span data-count="12"></span><span data-count="13"></span><span data-count="14"></span><span data-count="15"></span><span data-count="16"></span><span data-count="17"></span><span data-count="18"></span><span data-count="19"></span><span data-count="20"></span><span data-count="21"></span><span data-count="22"></span><span data-count="23"></span><span data-count="24"></span><span data-count="25"></span><span data-count="26"></span><span data-count="27"></span><span data-count="28"></span><span data-count="29"></span><span data-count="30"></span><span data-count="31"></span><span data-count="32"></span><span data-count="33"></span><span data-count="34"></span><span data-count="35"></span></div><pre><code class="hljs language-Python"><span class="hljs-comment"># SECURITY WARNING: keep the secret key used in production secret!</span>
<span class="hljs-keyword">with</span> <span class="hljs-built_in">open</span>(<span class="hljs-string">'/etc/[domaine]/secret_key.txt'</span>) <span class="hljs-keyword">as</span> f:
SECRET_KEY = f.read().strip()
<span class="hljs-comment"># SECURITY WARNING: don't run with debug turned on in production!</span>
DEBUG = <span class="hljs-literal">False</span>
ALLOWED_HOSTS = [<span class="hljs-string">'[domaine].fr'</span>,
<span class="hljs-string">'localhost'</span>,
<span class="hljs-string">'[ipv6]'</span>]
<span class="hljs-comment"># Database</span>
<span class="hljs-comment"># https://docs.djangoproject.com/en/4.0/ref/settings/#databases</span>
<span class="hljs-keyword">with</span> <span class="hljs-built_in">open</span>(<span class="hljs-string">'/etc/[domaine]/db_parameters.txt'</span>) <span class="hljs-keyword">as</span> f:
DATABASES = {
<span class="hljs-string">'default'</span>: {
<span class="hljs-string">'ENGINE'</span>: f.readline().strip(),
<span class="hljs-string">'NAME'</span>: f.readline().strip(),
<span class="hljs-string">'USER'</span>: f.readline().strip(),
<span class="hljs-string">'PASSWORD'</span>: f.readline().strip(),
<span class="hljs-string">'HOST'</span>: <span class="hljs-string">'127.0.0.1'</span>, <span class="hljs-comment"># Aussi testé avec '[domaine].fr'</span>
<span class="hljs-string">'PORT'</span>: f.readline().strip(),
}
}
<span class="hljs-comment"># DbBackup parameters:</span>
<span class="hljs-comment"># ====================</span>
DBBACKUP_STORAGE = <span class="hljs-string">'django.core.files.storage.FileSystemStorage'</span>
DBBACKUP_STORAGE_OPTIONS = {<span class="hljs-string">'location'</span>: <span class="hljs-string">'../../db_backup/'</span>}
DBBACKUP_CONNECTORS = {
<span class="hljs-string">'default'</span>: {
<span class="hljs-string">'HOST'</span>: <span class="hljs-string">'localhost'</span>
}
}
</code></pre></div>
<p>ma config site available/enabled :</p>
<div class="hljs-code-div hljs-code-text"><div class="hljs-line-numbers"><span data-count="1"></span><span data-count="2"></span><span data-count="3"></span><span data-count="4"></span><span data-count="5"></span><span data-count="6"></span><span data-count="7"></span><span data-count="8"></span><span data-count="9"></span><span data-count="10"></span><span data-count="11"></span><span data-count="12"></span><span data-count="13"></span><span data-count="14"></span><span data-count="15"></span><span data-count="16"></span></div><pre><code class="hljs language-text">upstream [domaine] {
server unix:/tmp/gunicorn.[domaine].sock fail_timeout=30s;
}
server {
listen 80; # SSL n’est pas encore configuré donc uniquement le port 80
server_name [domaine].fr;
access_log /var/log/nginx/[domaine].log;
error_log /var/log/nginx/[domaine].error.log;
location /static/ {
alias /home/[user]/django/[domaine]/blog/static/;
}
}
</code></pre></div>
<p>Et supervisor :</p>
<div class="hljs-code-div hljs-code-text"><div class="hljs-line-numbers"><span data-count="1"></span><span data-count="2"></span><span data-count="3"></span><span data-count="4"></span><span data-count="5"></span><span data-count="6"></span><span data-count="7"></span><span data-count="8"></span></div><pre><code class="hljs language-text">[program:[domaine]]
environment=DJANGO_SETTINGS_MODULE='Website.settings'
directory=/home/[user]/django/[domaine]/
command=/home/[user]/django/venv/bin/gunicorn --bind unix:/tmp/gunicorn.[domaine].sock --bind 127.0.0.1:8010 --workers 2 --log-file /var/log/gunicorn.[domaine].log Website.wsgi:application
autostart=true
autorestart=true
stdout_logfile=/var/log/[domaine].log
stderr_logfile=/var/log/[domaine].err.log
</code></pre></div>
<p>avec à chaque fois les vrais valeurs pour [domaine], [user] et [ipv6], bien évidement.</p>
<p>À noter que [user] correspond aussi à un utilisateur linux, sans droits roots (appelons le "webmaster"). </p>
<p>nginx, supervisor et postgre sont lancés par un autre utilisateur admin, avec sudo. Est-ce que ce n’est pas ça qui bloque ?</p>
<p>Aussi, lorsque je fait <code>curl localhost:8010</code>, je n’ai aucune réponse. Si je fais <code>curl localhost:8010/articles/</code> j’ai la page d’erreur 404 <em>de mon site</em> (la version customisée), ce qui est très étrange : ça signifie qu’il arrive à se connecter, mais pas à suivre l’url ???</p>
<p>En revanche, depuis un navigateur, j’ai toujours la page nginx à la racine, et un 404 standard (donc pas la page custom du site) à <code>[domaine].fr/articles</code></p>
<p>J’aurai donc tendance à pensé qu’il y a au moins deux problèmes.</p>
<p>EDIT : En passant momentanément à <code>DEBUG = True</code>, j’ai pu constaté qu’il y avait des petits problèmes mes vues. Des petits trucs qui fonctionnent bien avec une base de données déjà rempli, mais qui ne fonctionne plus avec une base de données vide. Bon à la limite c’est pas trop grave, c’est un problème que j’arriverai à résoudre.</p>
<p>Du coup si cherche à charger une page statique en local (<code>curl localhost:8010/contact/</code> par exemple), ça fonctionne normalement. Mais j’ai toujours mon problème à travers le navigateur d’une machine distante.</p>déployer une application web django, message #2505442023-05-24T22:28:44+02:001e49ba0eba/@1e49ba0ebahttps://zestedesavoir.com/forums/sujet/16972/deployer-une-application-web-django/?page=1#p250544<p>oui, j’ai mis les vrais valeurs.
Après est-ce qu’il faut bien mettre host et trust ? Est-ce qu’il y a juste l’ipv6 et le nom de domaine à autoriser ?</p>déployer une application web django, message #2505422023-05-24T20:47:27+02:00Drulac/@Drulachttps://zestedesavoir.com/forums/sujet/16972/deployer-une-application-web-django/?page=1#p250542<p>Coucou <img src="/static/smileys/svg/heureux.svg" alt=":D" class="smiley"> !</p>
<p>tu as bien remplacé les mots en accolades par tes valeurs dans <code>pg_hba.conf</code> ?</p>
<div class="hljs-code-div hljs-code-text"><pre><code class="hljs language-text">host [db] [user] [domaine] trust
</code></pre></div>déployer une application web django, message #2505392023-05-24T16:59:31+02:001e49ba0eba/@1e49ba0ebahttps://zestedesavoir.com/forums/sujet/16972/deployer-une-application-web-django/?page=1#p250539<p>Bonjour,</p>
<p>J’essaie de déployer un site web sous django.
J’ai suivi le tuto de <a href="https://zestedesavoir.com/tutoriels/2213/deployer-une-application-django-en-production/">ZdS</a></p>
<p>J’en suis au stade où je peux taper l’addresse du site dans un navigateur, ce qui m’amène sur </p>
<div class="hljs-code-div hljs-code-text"><div class="hljs-line-numbers"><span data-count="1"></span><span data-count="2"></span><span data-count="3"></span><span data-count="4"></span><span data-count="5"></span><span data-count="6"></span><span data-count="7"></span><span data-count="8"></span></div><pre><code class="hljs language-text">Welcome to nginx!
If you see this page, the nginx web server is successfully installed and working. Further configuration is required.
For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.
Thank you for using nginx.
</code></pre></div>
<p>Donc a priori, Nginx fonctionne.
Je pense que je suis bon du côté de supervizor et gunicorn et j’ai l’impression que le problème viens de postgresql.</p>
<p>Voici l’erreur donnée par gunicorn:</p>
<div class="hljs-code-div hljs-code-text"><pre><code class="hljs language-text">psycopg2.OperationalError: connection to server at "[domaine]" ([ipv6]), port 5432 failed: FATAL: no pg_hba.conf entry for host "[ipv6]", user "[user]", database "[db]", SSL on
</code></pre></div>
<p>J’ai essayé de modifier le fichiers pg_hba.conf en ajoutant</p>
<div class="hljs-code-div hljs-code-text"><pre><code class="hljs language-text">host [db] [user] [domaine] trust
</code></pre></div>
<p>ou</p>
<div class="hljs-code-div hljs-code-text"><pre><code class="hljs language-text">host [db] [user] [ipv6] trust
</code></pre></div>
<p>ainsi que quelques autres tests.
Ça ne change rien à part que je n’arrive même plus à me connecter en local :</p>
<div class="hljs-code-div hljs-code-text"><div class="hljs-line-numbers"><span data-count="1"></span><span data-count="2"></span><span data-count="3"></span></div><pre><code class="hljs language-text">psql: error: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
</code></pre></div>
<p>et le message d’erreur du log de gunicorn devient :</p>
<div class="hljs-code-div hljs-code-text"><div class="hljs-line-numbers"><span data-count="1"></span><span data-count="2"></span></div><pre><code class="hljs language-text">psycopg2.OperationalError: connection to server at "[domaine]" (ipv6), port 5432 failed: Connection refused
Is the server running on that host and accepting TCP/IP connections?
</code></pre></div>
<p>Ça commence à faire quelques heures que je tourne en rond. Si quelqu’un à une solution…</p>
<p>en vous remerciant.</p>Latex vers html sans javascript., message #2496482023-03-20T13:57:10+01:00Amaury/@Amauryhttps://zestedesavoir.com/forums/sujet/16869/latex-vers-html-sans-javascript/?page=1#p249648<p>J’ignorais son existence, merci de l’avoir partagée ! Je note, ça peut toujours servir <img src="/static/smileys/svg/smile.svg" alt=":)" class="smiley"></p>Latex vers html sans javascript., message #2496422023-03-19T21:55:33+01:001e49ba0eba/@1e49ba0ebahttps://zestedesavoir.com/forums/sujet/16869/latex-vers-html-sans-javascript/?page=1#p249642<p>Bonsoir,</p>
<p>J’avais effectivement finit par tomber sur Katex dans les dépots de ZdS après avoir posté mon message. Sans savoir comment l’exploiter.</p>
<p>Je connais très mal Javascript et je n’ai jamais utilisé NodeJS. Du coup j’ai regardé s’il y avait des chose côté Python et je suis tombé sur <a href="https://pypi.org/project/markdown-katex/">cette extension</a>. Un <code>pip install</code> et c’est réglé. Vraiment pas mal.</p>Latex vers html sans javascript., message #2495682023-03-14T15:24:36+01:00Amaury/@Amauryhttps://zestedesavoir.com/forums/sujet/16869/latex-vers-html-sans-javascript/?page=1#p249568<p>Note en passant — Tu n’as pas trouvé sur le GitHub de ZdS probablement car tu as dû regarder <a href="https://github.com/zestedesavoir/zds-site">le code source du site</a>. <span class="math math-inline"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mtext>KaTeX</mtext></mrow><annotation encoding="application/x-tex">\KaTeX</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.89883em;vertical-align:-0.2155em;"></span><span class="mord text"><span class="mord textrm">K</span><span class="mspace" style="margin-right:-0.17em;"></span><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.68333em;"><span style="top:-2.904999em;"><span class="pstrut" style="height:2.7em;"></span><span class="mord"><span class="mord textrm mtight sizing reset-size6 size3">A</span></span></span></span></span></span><span class="mspace" style="margin-right:-0.15em;"></span><span class="mord text"><span class="mord textrm">T</span><span class="mspace" style="margin-right:-0.1667em;"></span><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.46782999999999997em;"><span style="top:-2.7845em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord textrm">E</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.2155em;"><span></span></span></span></span><span class="mspace" style="margin-right:-0.125em;"></span><span class="mord textrm">X</span></span></span></span></span></span></span> est intégré dans zmd, notre moteur Markdown, qui est <a href="https://github.com/zestedesavoir/zmarkdown">dans un dépôt séparé</a>. Et pour être honnête, il faut un peu creuser, car <span class="math math-inline"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mtext>KaTeX</mtext></mrow><annotation encoding="application/x-tex">\KaTeX</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.89883em;vertical-align:-0.2155em;"></span><span class="mord text"><span class="mord textrm">K</span><span class="mspace" style="margin-right:-0.17em;"></span><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.68333em;"><span style="top:-2.904999em;"><span class="pstrut" style="height:2.7em;"></span><span class="mord"><span class="mord textrm mtight sizing reset-size6 size3">A</span></span></span></span></span></span><span class="mspace" style="margin-right:-0.15em;"></span><span class="mord text"><span class="mord textrm">T</span><span class="mspace" style="margin-right:-0.1667em;"></span><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.46782999999999997em;"><span style="top:-2.7845em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord textrm">E</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.2155em;"><span></span></span></span></span><span class="mspace" style="margin-right:-0.125em;"></span><span class="mord textrm">X</span></span></span></span></span></span></span> est caché derrière les dépendances <code>rehype-katex</code> et <code>remark-math</code>…</p>Latex vers html sans javascript., message #2495672023-03-14T15:02:16+01:00ache/@achehttps://zestedesavoir.com/forums/sujet/16869/latex-vers-html-sans-javascript/?page=1#p249567<p>Il me semble que MathML n’était pas supporté par Chrome mais que ça vient de changer tout récemment. J’ai hâte de tester. J’utilise <span class="math math-inline"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mtext>KaTeX</mtext></mrow><annotation encoding="application/x-tex">\KaTeX</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.89883em;vertical-align:-0.2155em;"></span><span class="mord text"><span class="mord textrm">K</span><span class="mspace" style="margin-right:-0.17em;"></span><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.68333em;"><span style="top:-2.904999em;"><span class="pstrut" style="height:2.7em;"></span><span class="mord"><span class="mord textrm mtight sizing reset-size6 size3">A</span></span></span></span></span></span><span class="mspace" style="margin-right:-0.15em;"></span><span class="mord text"><span class="mord textrm">T</span><span class="mspace" style="margin-right:-0.1667em;"></span><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.46782999999999997em;"><span style="top:-2.7845em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord textrm">E</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.2155em;"><span></span></span></span></span><span class="mspace" style="margin-right:-0.125em;"></span><span class="mord textrm">X</span></span></span></span></span></span></span> personnellement et si je peux me passer du CSS en plus, je dis pas non.</p>
<p>Ayant les même exigences que toi <a href="/@1e49ba0eba" rel="nofollow" class="ping ping-link">@<span class="ping-username">1e49ba0eba</span></a>, je te confirme que <span class="math math-inline"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mtext>KaTeX</mtext></mrow><annotation encoding="application/x-tex">\KaTeX</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.89883em;vertical-align:-0.2155em;"></span><span class="mord text"><span class="mord textrm">K</span><span class="mspace" style="margin-right:-0.17em;"></span><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.68333em;"><span style="top:-2.904999em;"><span class="pstrut" style="height:2.7em;"></span><span class="mord"><span class="mord textrm mtight sizing reset-size6 size3">A</span></span></span></span></span></span><span class="mspace" style="margin-right:-0.15em;"></span><span class="mord text"><span class="mord textrm">T</span><span class="mspace" style="margin-right:-0.1667em;"></span><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.46782999999999997em;"><span style="top:-2.7845em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord textrm">E</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.2155em;"><span></span></span></span></span><span class="mspace" style="margin-right:-0.125em;"></span><span class="mord textrm">X</span></span></span></span></span></span></span> fait le taf. Il faut cependant noter une légère incompatibilité avec <span class="math math-inline"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mtext>LaTeX</mtext></mrow><annotation encoding="application/x-tex">\LaTeX</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.89883em;vertical-align:-0.2155em;"></span><span class="mord text"><span class="mord textrm">L</span><span class="mspace" style="margin-right:-0.36em;"></span><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.68333em;"><span style="top:-2.904999em;"><span class="pstrut" style="height:2.7em;"></span><span class="mord"><span class="mord textrm mtight sizing reset-size6 size3">A</span></span></span></span></span></span><span class="mspace" style="margin-right:-0.15em;"></span><span class="mord text"><span class="mord textrm">T</span><span class="mspace" style="margin-right:-0.1667em;"></span><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.46782999999999997em;"><span style="top:-2.7845em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord textrm">E</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.2155em;"><span></span></span></span></span><span class="mspace" style="margin-right:-0.125em;"></span><span class="mord textrm">X</span></span></span></span></span></span></span>.</p>Latex vers html sans javascript., message #2495642023-03-14T13:48:50+01:00Amaury/@Amauryhttps://zestedesavoir.com/forums/sujet/16869/latex-vers-html-sans-javascript/?page=1#p249564<p>Salut !</p>
<p>ZdS utilise <a href="https://katex.org">un logiciel appelé <span class="math math-inline"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mtext>KaTeX</mtext></mrow><annotation encoding="application/x-tex">\KaTeX</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.89883em;vertical-align:-0.2155em;"></span><span class="mord text"><span class="mord textrm">K</span><span class="mspace" style="margin-right:-0.17em;"></span><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.68333em;"><span style="top:-2.904999em;"><span class="pstrut" style="height:2.7em;"></span><span class="mord"><span class="mord textrm mtight sizing reset-size6 size3">A</span></span></span></span></span></span><span class="mspace" style="margin-right:-0.15em;"></span><span class="mord text"><span class="mord textrm">T</span><span class="mspace" style="margin-right:-0.1667em;"></span><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.46782999999999997em;"><span style="top:-2.7845em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord textrm">E</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.2155em;"><span></span></span></span></span><span class="mspace" style="margin-right:-0.125em;"></span><span class="mord textrm">X</span></span></span></span></span></span></span></a>. C’est un logiciel en JavaScript, mais il supporte ce qu’on appelle le <em><a href="https://katex.org/docs/api.html#server-side-rendering-or-rendering-to-a-string">server-side rendering</a></em>, donc le fait de générer le HTML correspondant aux formules de maths côté serveur, en amont. Il suffit derrière d’inclure le CSS de <span class="math math-inline"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mtext>KaTeX</mtext></mrow><annotation encoding="application/x-tex">\KaTeX</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.89883em;vertical-align:-0.2155em;"></span><span class="mord text"><span class="mord textrm">K</span><span class="mspace" style="margin-right:-0.17em;"></span><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.68333em;"><span style="top:-2.904999em;"><span class="pstrut" style="height:2.7em;"></span><span class="mord"><span class="mord textrm mtight sizing reset-size6 size3">A</span></span></span></span></span></span><span class="mspace" style="margin-right:-0.15em;"></span><span class="mord text"><span class="mord textrm">T</span><span class="mspace" style="margin-right:-0.1667em;"></span><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.46782999999999997em;"><span style="top:-2.7845em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord textrm">E</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.2155em;"><span></span></span></span></span><span class="mspace" style="margin-right:-0.125em;"></span><span class="mord textrm">X</span></span></span></span></span></span></span> et ça roule. C’est ce qu’on fait.</p>
<p>Par contre, il faut toujours du JS. Simplement, ce sera NodeJS, pas le navigateur du visiteur. <span class="math math-inline"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mtext>KaTeX</mtext></mrow><annotation encoding="application/x-tex">\KaTeX</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.89883em;vertical-align:-0.2155em;"></span><span class="mord text"><span class="mord textrm">K</span><span class="mspace" style="margin-right:-0.17em;"></span><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.68333em;"><span style="top:-2.904999em;"><span class="pstrut" style="height:2.7em;"></span><span class="mord"><span class="mord textrm mtight sizing reset-size6 size3">A</span></span></span></span></span></span><span class="mspace" style="margin-right:-0.15em;"></span><span class="mord text"><span class="mord textrm">T</span><span class="mspace" style="margin-right:-0.1667em;"></span><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.46782999999999997em;"><span style="top:-2.7845em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord textrm">E</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.2155em;"><span></span></span></span></span><span class="mspace" style="margin-right:-0.125em;"></span><span class="mord textrm">X</span></span></span></span></span></span></span> supporte également le rendu côté client (et de façon <em>bien</em> plus performante que MathJAX), à toutes fins utiles, même si tu disais que ce n’était pas ce qui t’intéresse ici.</p>
<p>Autre solution (utilisée par <span class="math math-inline"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mtext>KaTeX</mtext></mrow><annotation encoding="application/x-tex">\KaTeX</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.89883em;vertical-align:-0.2155em;"></span><span class="mord text"><span class="mord textrm">K</span><span class="mspace" style="margin-right:-0.17em;"></span><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.68333em;"><span style="top:-2.904999em;"><span class="pstrut" style="height:2.7em;"></span><span class="mord"><span class="mord textrm mtight sizing reset-size6 size3">A</span></span></span></span></span></span><span class="mspace" style="margin-right:-0.15em;"></span><span class="mord text"><span class="mord textrm">T</span><span class="mspace" style="margin-right:-0.1667em;"></span><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.46782999999999997em;"><span style="top:-2.7845em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord textrm">E</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.2155em;"><span></span></span></span></span><span class="mspace" style="margin-right:-0.125em;"></span><span class="mord textrm">X</span></span></span></span></span></span></span>, et donc ici, en sous-main) : <a href="https://developer.mozilla.org/fr/docs/Web/MathML">MathML, une norme pour insérer des maths dans un navigateur</a> (<a href="https://developer.mozilla.org/en-US/docs/Web/MathML">en anglais</a>). Cela dit, c’est beaucoup moins simple à utiliser que le format <span class="math math-inline"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mtext>LaTeX</mtext></mrow><annotation encoding="application/x-tex">\LaTeX</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.89883em;vertical-align:-0.2155em;"></span><span class="mord text"><span class="mord textrm">L</span><span class="mspace" style="margin-right:-0.36em;"></span><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.68333em;"><span style="top:-2.904999em;"><span class="pstrut" style="height:2.7em;"></span><span class="mord"><span class="mord textrm mtight sizing reset-size6 size3">A</span></span></span></span></span></span><span class="mspace" style="margin-right:-0.15em;"></span><span class="mord text"><span class="mord textrm">T</span><span class="mspace" style="margin-right:-0.1667em;"></span><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.46782999999999997em;"><span style="top:-2.7845em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord textrm">E</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.2155em;"><span></span></span></span></span><span class="mspace" style="margin-right:-0.125em;"></span><span class="mord textrm">X</span></span></span></span></span></span></span> — il faut aimer XML… Mais ça marche sans script, tel quel. Et autre avantage, les maths en MathML sont accessibles (aux lecteurs d’écran, etc.). <a href="http://eyeasme.com/Joe/MathML/MathML_browser_test.html">Cette page donne plein d’exemples</a>, tu peux en inspecter le code source pour voir quelle tête ça a concrètement.</p>
<p>C’est pour ça que <span class="math math-inline"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mtext>KaTeX</mtext></mrow><annotation encoding="application/x-tex">\KaTeX</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.89883em;vertical-align:-0.2155em;"></span><span class="mord text"><span class="mord textrm">K</span><span class="mspace" style="margin-right:-0.17em;"></span><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.68333em;"><span style="top:-2.904999em;"><span class="pstrut" style="height:2.7em;"></span><span class="mord"><span class="mord textrm mtight sizing reset-size6 size3">A</span></span></span></span></span></span><span class="mspace" style="margin-right:-0.15em;"></span><span class="mord text"><span class="mord textrm">T</span><span class="mspace" style="margin-right:-0.1667em;"></span><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.46782999999999997em;"><span style="top:-2.7845em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord textrm">E</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.2155em;"><span></span></span></span></span><span class="mspace" style="margin-right:-0.125em;"></span><span class="mord textrm">X</span></span></span></span></span></span></span> compile vers MathML pour toi. Enfin plus précisément, <span class="math math-inline"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mtext>KaTeX</mtext></mrow><annotation encoding="application/x-tex">\KaTeX</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.89883em;vertical-align:-0.2155em;"></span><span class="mord text"><span class="mord textrm">K</span><span class="mspace" style="margin-right:-0.17em;"></span><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.68333em;"><span style="top:-2.904999em;"><span class="pstrut" style="height:2.7em;"></span><span class="mord"><span class="mord textrm mtight sizing reset-size6 size3">A</span></span></span></span></span></span><span class="mspace" style="margin-right:-0.15em;"></span><span class="mord text"><span class="mord textrm">T</span><span class="mspace" style="margin-right:-0.1667em;"></span><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.46782999999999997em;"><span style="top:-2.7845em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord textrm">E</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.2155em;"><span></span></span></span></span><span class="mspace" style="margin-right:-0.125em;"></span><span class="mord textrm">X</span></span></span></span></span></span></span> fait une double-compilation : une en MathML, qui est masquée en CSS et qui sert quand ce dernier est désactivé (comme tu l’as constaté), et pour l’accessibilité ; et une en HTML/CSS, un peu plus jolie, plus dans le style <span class="math math-inline"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mtext>LaTeX</mtext></mrow><annotation encoding="application/x-tex">\LaTeX</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.89883em;vertical-align:-0.2155em;"></span><span class="mord text"><span class="mord textrm">L</span><span class="mspace" style="margin-right:-0.36em;"></span><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.68333em;"><span style="top:-2.904999em;"><span class="pstrut" style="height:2.7em;"></span><span class="mord"><span class="mord textrm mtight sizing reset-size6 size3">A</span></span></span></span></span></span><span class="mspace" style="margin-right:-0.15em;"></span><span class="mord text"><span class="mord textrm">T</span><span class="mspace" style="margin-right:-0.1667em;"></span><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.46782999999999997em;"><span style="top:-2.7845em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord textrm">E</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.2155em;"><span></span></span></span></span><span class="mspace" style="margin-right:-0.125em;"></span><span class="mord textrm">X</span></span></span></span></span></span></span>.</p>Latex vers html sans javascript., message #2495622023-03-14T12:03:00+01:001e49ba0eba/@1e49ba0ebahttps://zestedesavoir.com/forums/sujet/16869/latex-vers-html-sans-javascript/?page=1#p249562<p>Bonjour,</p>
<p>J’aimerai pouvoir utiliser du <span class="math math-inline"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>L</mi><mi>a</mi><mi>t</mi><mi>e</mi><mi>x</mi></mrow><annotation encoding="application/x-tex">Latex</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord mathdefault">L</span><span class="mord mathdefault">a</span><span class="mord mathdefault">t</span><span class="mord mathdefault">e</span><span class="mord mathdefault">x</span></span></span></span></span> dans une page
web. En recherchant sur internet, la solution la plus simple semble être d’ajouter un script mathjax dans la page.</p>
<p>Je n’aime pas trop utiliser des script externes. Corrélation n’est pas causalité, mais la corrélation inverse entre la qualité d’une page web et la quantité de script qu’elle contient est tout de même notoire aujourd’hui.</p>
<p>Je vois que sur le ZdS et Wikipédia, les formules s’affichent correctement, même lorsque javascript et css sont complètement désactivé. J’en déduis que la conversion est faite côté serveur. J’ai essayé de faire un tour sur le Github de ZdS (qui utilise django, comme moi), mais je n’arrive à comprendre comment cela est fait ?</p>
<p>Quel module devrais-je utiliser ?</p>
<p>Merci.</p>Quel serveur mail ?, message #2484372023-01-17T07:37:37+01:00antalyaera2/@antalyaera2https://zestedesavoir.com/forums/sujet/5781/quel-serveur-mail/?page=1#p248437<p>Nice article, thanks for the information. If you are interested in real estate investment in Turkey. I definitely recommend looking <a href="https://tolerance-homes.com/turkey/antalya/villas/">villa in antalya</a>.</p>pleins de questions sur le déploiement d’une application django, message #2479132022-12-25T22:51:34+01:00Amaury/@Amauryhttps://zestedesavoir.com/forums/sujet/16694/pleins-de-questions-sur-le-deploiement-dune-application-django/?page=1#p247913<p>Avec plaisir ! Je passe ton sujet en résolu, n’hésite pas à annuler si tu as d’autres questions <img src="/static/smileys/svg/smile.svg" alt=":)" class="smiley"></p>pleins de questions sur le déploiement d’une application django, message #2479052022-12-25T18:53:57+01:001e49ba0eba/@1e49ba0ebahttps://zestedesavoir.com/forums/sujet/16694/pleins-de-questions-sur-le-deploiement-dune-application-django/?page=1#p247905<p>Ça a l’air d’être ça. Bien vu !</p>