#Django3
Explore tagged Tumblr posts
nshbrown · 4 years ago
Text
Model Versioning with Diff’s in Django v3_1
Created: March 20, 2021 
Modified: March 22, 2021
 What we start with is a simple model that has two fields; a title and a body. What we end up with is a collection of modifications done that allows us to see what changed in both fields for each modification performed. This is enabled by a plugin called django-simple-history and then leveraged with diff behind the scenes to give readability into what changed between the title and the body from version to version. In this article we will be leveraging the diff command in Ubuntu with Django version 3.1 via a command line utility that captures the output and then we use it to show in the view template after it has been cleaned up and made ready for HTML. At this point there is no caching and assumes your website will have very little traffic. More on that possibility in a later article.
Continuing with the document called Custom item URL’s in Django v3_1, get your app started
1.      Start the Hyper-V in the Windows Search bar
Tumblr media
2.      Double click the name Ubuntu Server 20.4 LTS and it should launch a screen that is a terminal
3.      Login if required, in other words if it is not already logged in
4.      Change into the ~/OneDrive/code/example.com/git/project
5.      Update to the latest version of Django
Tumblr media
a.      python3.8 -m pip install django==3.1.7
6.      Run the server on the 8000 port
a.      python3.8 manage.py runserver 0:8000
Tumblr media
7.      Load the site in your browser
a.      http://192.168.0.12:8000/
Continue to build the poems app
1.      Run the install command and get the django-simple-hijstory module installed
a.      python3.8 -m pip install django-simple-history
2.      Modify the project/project/settings_development.py and add to the INSTALLED_APPS
3.      Add the HistoryRequestMiddleware to the MIDDLEWARE variable in the same document so we can automatically track changes done by each user within the history.
4.      Add HistoricalRecords() call to the Poem model poems/models.py
5.      Run the migrations to get the database ready
a.      python3.8 manage.py makemigrations
Tumblr media
b.      python3.8 manage.py migrate
Tumblr media
6.      As found by referencing Kite [1] and Stack Overflow [2] and several other sources as mentioned at the end of the document to make this code concise; here’s how to get the diff of a change made by capturing the output of the command line from within your new view method in poems/views.py. This presumes your Poem will have multiple lines to compare with.
7.      Add the following to poems/templatetags/poem_tag_extras.py as found on Stack Overflow [12]
8.      Modify the poems/templates/poems/item.html to reflect all the changes of the item
9.      Now run the populate_history command to get all the Poem data imported relative to the fixture we loaded in the previous article..
Tumblr media
There you have it, a site that shows the differences between each version of change due to modifying either the title or the body of the Poem record. Thank you for reading this document. Please reach out to me by TXT message at 250-368-1324 and let me know if you had any questions and I will update where the article needs to be clarified.
   Sources:
Note to the sources; Thank you very much! I really appreciate the contributions you each have made to the Python and Django community. If by chance I have used your research material in error, please contact me at the above-mentioned TXT number and I will refactor the article to coincide with any agreements I may have misunderstood. My apologies in advance.
[1] https://www.kite.com/python/answers/how-to-get-output-from-a-shell-command-in-python
[2] https://stackoverflow.com/questions/23929235/multi-line-string-with-extra-space-preserved-indentation
[3] https://getbootstrap.com/docs/4.0/utilities/text/
[4] https://stackoverflow.com/questions/3877623/in-python-can-you-have-variables-within-triple-quotes-if-so-how
[5] https://stackoverflow.com/questions/46781136/syntax-error-near-unexpected-token-when-using-multiple-input-streams-from-zc
[6] https://stackoverflow.com/questions/7011066/get-the-last-element-of-the-list-in-django
[7] https://stackoverflow.com/questions/11481499/django-iterate-number-in-for-loop-of-a-template
[8] https://docs.python.org/3/tutorial/controlflow.html
[9] https://stackoverflow.com/questions/23929235/multi-line-string-with-extra-space-preserved-indentation
[10] https://stackoverflow.com/questions/1107737/numeric-for-loop-in-django-templates
[11] https://docs.python.org/3/library/pprint.html
[12] https://stackoverflow.com/questions/13358063/template-tag-or-filter
[13] https://www.djangoproject.com/download/
[14] https://www.programiz.com/python-programming/methods/list/reverse
0 notes
debsdaniel03 · 5 years ago
Text
https://www.udemy.com/course/experto-en-vuejs-con-django-rest-framework/?referralCode=8BDCEC50053221F3E22D
Tumblr media
📣#cursovirtual #cursoonline #Aprende a Desarrollar #frontend con #vuejs y #backend con #Django #restful de #Python
🎙#Precio #Oficial en @Udemy_es
🖲#javascript #js #restapi #webdevelopment #nodejs
🔎 https://www.udemy.com/course/experto-en-vuejs-con-django-rest-framework/?referralCode=8BDCEC50053221F3E22D
0 notes
sololinuxes · 5 years ago
Text
Cyberpanel 2.0 - La nueva versión del panel de control web
Tumblr media
Cyberpanel 2.0 - La nueva versión del panel de control web. A pesar de la crisis de COVID-19, el equipo de desarrolladores del panel de control web Cyberpanel nos presenta su nueva versión. Al estar en casa confinados parece que el trabajo se ha acelerado de forma considerable, pues la versión prevista era la 1.95, pero dado las grandes modificaciones y mejoras han decidido saltar directamente a la 2.0. Sobran las palabras sobre una aplicación en la que priman la velocidad y seguridad, aún así el nivel de seguridad a subido enormemente. Las mejoras son muchas y algunas sorprendentes, estas son las mejoras que más nos llaman la atención. Sincronización con CloudFlare DNS Redis Mass Hosting - Util para no tener que reiniciar el panel cuando se agrega un nuevo dominio. Integración de CloudLinux + Imunify360 Git Manager  Automatización Git Webhooks Servidor de correo para enviar las notificaciones del servidor Gestión de las colas de correo Migrar desde EasyEngine de forma simple Estadísticas y logs de los dominios También se agrega soporte para Python 3 y Django 3 entre otras mejoras. Puedes ver la lista completa en su página oficial. Como ya comentamos, la seguridad es fundamental para el equipo de Cyberpanel, así que optaron por contratar un experto en seguridad para verificar concienzudamente la herramientas y hacer las correcciones necesarias. En sololinux ya hemos realizado varios artículos sobre este fantástico panel de control web, tal vez te interese revisar alguno de ellos. Puedes verlos aquí.   Canales de Telegram: Canal SoloLinux – Canal SoloWordpress Espero que este articulo te sea de utilidad, puedes ayudarnos a mantener el servidor con una donación (paypal), o también colaborar con el simple gesto de compartir nuestros artículos en tu sitio web, blog, foro o redes sociales.   Read the full article
0 notes
maonanda · 5 years ago
Photo
Tumblr media
#latepost Saliendo del cine termine así D8 #django3 gracias por la foto @valhrean <3 https://www.instagram.com/p/B54ULFzAWMb/?igshid=wdvi8l6cqtq0
0 notes
las-skywalker · 6 years ago
Photo
Tumblr media
Salió el póster oficial de la tercera entrega de Django que ahora se llamará: Django en el nombre del hijo. 🎬Sinopsis: Se privó de la libertad para salvar a su hijo. Ahora Django se privará de su propia identidad, dejará de existir para el mundo. Quiere darle una vida mejor a su familia. #las_movie #skywalkerlovers #django3. https://www.instagram.com/p/B217kW2J4Jl/?igshid=vsntbsui8sug
0 notes
guangyaw · 5 years ago
Text
Django3.0 正式 Release
Django 3.0 在 2019/12/02 正式釋出,
發布了許多新功能以外,
對於舊有的 Python 2 也不予支持,
當然第三方的支持還是能用的,
需要更詳細的 release note 可到官方網站觀看
此處僅列出幾個要點。
Tumblr media
而官方網站也同時釋出��� Django 2.2.8 ,
此版本同時也是 Django 2.2 的最後錯誤修正版本
底下為官方釋出的更新時程表:
Tumblr media
Django 3.0 的主要變更有:
對 ASGI 的支持讓 Djano 具有完整的異步功能
正式支援 MariaDB 10.1 及更新版本
輸出BooleanField的表達式,可以直接在QuerySet過濾器中使用
次要的變更:
django.contrib.admin:
在…
View On WordPress
0 notes
pahrak-the-sinnoh-slizer · 2 years ago
Text
Finally made it to the Graveyard, and finally got Collect, which means it’s time to round up the last few chips and PAs I need.  JudgeMan is being a bitch and won’t spawn, so that’s an issue...plus I’m going to need to do the rest of the Virus Battlers (in Japanese) to get Django3...and there are a surprising number of chips I need BugFrags to get my hands on...perhaps the worst one, though, is that to get a chip in a certain code I need for a PA, I’m gonna have to constantly refresh GMDs in Underground 2.  And there is no quick way to get to Underground 2.  So that’s lovely.
1 note · View note
bpbobline · 5 years ago
Photo
Tumblr media
Behold the big reveal: Amazing Authors and Their Upcoming Books To Read in 2020 at BPBOnline 
BPB Publications #Books #Writing #Ebook #MustRead #authors #techbooks #technology #newbook #upcoming #microservices #Django3 #Python #framework #kotlin #interview #interviewtips #interviewquestions #career #jobs #data #security #electronics #coding #development #software
0 notes
rmariovos · 8 years ago
Text
http://twitter.com/barrioAlmendros/status/856187346856943622
Un puente aéreo de cerveza https://t.co/8UF4iwMCrI https://t.co/ocLxPeO5la Django33, Abril 23, 2017, 11:33 am April 23, 2017 at 12:33PM
— Medellín, Colombia (@barrioAlmendros) April 23, 2017
from Twitter https://twitter.com/barrioAlmendros April 23, 2017 at 12:45PM via barrioAlmendros
0 notes
nshbrown · 4 years ago
Text
Custom item URL’s in Django v3_1
This article explains how to setup custom item URL’s such as /poem-My%20Favorite%Place-1 in order to allow Search Indexes such as Google to get to your website from the root / directory for all the content. I am running a test right now to see if this is more efficient for the Search Indexes or not.
Get the app started in your webserver so you can do changes and check immediately
1.      Start the Hyper-V in the Windows Search bar
2.      Double click the icon that looks like a screen under the Ubuntu Server 20.04 LTS tab in the middle
3.      Login if required
4.      Launch the server
5.      Change into the ~/OneDrive/code/example.com/git
6.      python3.8 manage.py runserver 0:8000
7.      Load the site in your browser
8.      http://192.168.0.12:8000/
Build the poems app
1.      python3.8 manage.py startapp poems
2.      Modify the poems/views.py
a.      from django.shortcuts import get_object_or_404
b.      from .models import Poem
c.      def index(request):
d.                   poems_created = Poem.objects.exclude(hidden=True).order_by('created').reverse()
e.                   options = {
f.                                   'poems': poems_created,
g.                   }
h.                   return render(request, 'poems/index.html', options)
i.        
j.       def item(request, poem_id):
k.                   poem = get_object_or_404(Poem, pk=poem_id)
l.        
m.                 options = {
n.                                  'poem': poem,
o.                                  'poem_id': poem_id,
p.                   }
q.                   return render(request, 'poems/item.html', options)
3.      Add a new directory called templates in the root of the project at the same level as poems
4.      Create a file called templates/theme.html
a.      {% load static %}
b.      <!doctype html>
c.      <html lang="en">
d.                   <head>
e.                                  <title>My Poems</title>
f.                                   <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
g.                                  <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.bundle.min.js" crossorigin="anonymous"></script>
h.                   </head>
i.                    <body class="d-flex flex-column h-100">
j.                                   {% block content %}
k.                                  {% endblock %}
l.                    </body>
m.    </html>
5.      Modify the poems/models.py
a.      from django.db import models
b.      
d.      class Poem(models.Model):
e.                   title = models.CharField(max_length=255)
f.                    body = models.TextField()
g.       
h.                   def str(self):              
i.                                   return self.title
6.      Make the migrations and run them
a.      python3.8 manage.py makemigrations
b.      python3.8 manage.py migrate
7.      Create a template for the poems app index page at poems/templates/poems/index.html
a.      {% extends 'theme.html' %}
b.      {% load static %}
c.      {% load poem_tag_extras %}
d.      {% block content %}
e.      <main role="main" class="flex-shrink-0 pt-2">
f.                    <div class="container-md">
g.                                  <h1>My Poems</h1>
h.                                  <ul class="list-group">
i.                        {% for poem in poems %}
j.                                                  <li class="list-group-item d-flex justify-content-between">
k.                                                                <span class="bold"><a href="{{ poem|poem_item_url:request }}">"{{ poem.title }}"</a></span>
l.                                                  </li>
m.                     {% endfor %}
n.                   </ul>
o.                   </div>
p.      </main>
q.      {% endblock %}
8.      Create a template file for each Poem item at poems/templates/poems/item.html
a.      {% extends 'theme.html' %}
b.      {% load static %}
c.      {% load poem_tag_extras %}
d.      {% block content %}
e.      <main role="main" class="flex-shrink-0 pt-2">
f.                    <div class="container-md">
g.                                  <h1><a href="/">My Poems</a></h1>
h.                   <div class="col mb-4">
i.                                                  <div class="card h-100 my-2 mx-3">                                                    
j.                                                      <div class="card-body" id="poem-{{poem.id}}">
k.                                                                <a name="poem-{{poem.id}}"></a>
l.                                                                                <h5 class="card-title">{{ poem.title }}</h5>
m.                                                                             <div class="card-text">{{ poem.body|linebreaks }}</div>
n.                                                                </div>
o.                                                 </div>
p.                                  </div>
q.                                  <h4><a href="/#poems">View All Poems</a></h4>
r.                    </div>
s.      </main>
t.       {% endblock %}
9.      Create a new directory for the custom template tag used in the poems/index.html document at the poems/templatetags/poem_tag_extras.py. Also don’t forget to create a init.py document so it loads the directory properly.
a.      from django import template
b.      import re
c.      import urllib
d.      from poems.models import Poem
e.       
f.       register = template.Library()
g.       
h.      @register.filter(takes_context=True)
i.       def poem_item_url(poem, request):
j.                    if type(poem) == Poem:
k.                                  poem_id = poem.id
l.                                   poem_title = poem.title
m.                 else:
n.                                  return False
o.       
p.                   host = request.META['HTTP_HOST']
q.       
r.                    if "inlovelike" in host:
s.                                  host = "https://" + host + "/"
t.                    else:
u.                                  host = "http://" + host + "/"
v.       
w.                 return host + "poem-" + urllib.parse.quote_plus(poem_title)[:255] + "-" + str(poem_id)
10.   Modify the poems/admin.py to include the Poem model
a.      from django.contrib import admin
b.      from .models import Poem
c.       
d.      admin.site.register(Poem)
11.   Modify your project name’s app urls.py file (Eg. /myapp/myapp/urls.py) so that it includes the shorthand (Eg. /poem-My%Title-1)
a.      from django.urls import include, path, re_path
b.      from poems import views as poem_views
c.       
d.      urlpatterns = [
e.         …
f.          re_path(r'^poem-.*-(?P<poem_id>\d+)$', poem_views.item, name="poem_item"),
h.     # path('poems/', include('poems.urls')),
i.       ]
12.   Create a fixture for the import of some dummy data to play with in the interface at /myapp/fixtures/poems_poem.json
a.      [{"model": "poems.poem", "pk": 1, "fields": {"title": "My First Poem", "body": "Here\r\nI\r\nStart"}}, {"model": "poems.poem", "pk": 2, "fields": {"title": "My Second Poem", "body": "This\r\n\Is\r\nA\r\nPoem"}}}]
13.   Run the loaddata command to get your content into the database
a.      python3.8 manage.py loaddata poems_poem.json
Now here is a project that has poems linked to the nested pages off the root directory of the homepage.
PS. This is live in action on https://inlovelike.com, please do take a look.
PSS. The file paths mentioned now have links to code so you can copy/paste them more simply. I do not have a template yet for Tumblr to create an article. If and when I do, they will be inline code example.
0 notes
nshbrown · 4 years ago
Text
Setting up a 404 error handler and others in Django v3_1
Assuming you have already read the “Installing Python 3 & Django 3 with “Hello World” remotely on Plesk Obsidian and locally on Ubuntu Server 20.04 LTS running Windows 10 Pro’s Hyper-V” document on how to get a “Hello World” Django application setup and running; here is how to get that app working even better if you have traffic that you may have lost at one point or another due to missing redirects when content shifts from one URL to another.
Get the project/app/views.py
1.      Start the Hyper-V in the Windows Search bar
2.      Double click the icon that looks like a screen under the Ubuntu Server 20.04 LTS tab in the middle
3.      Login if required
4.      Launch the server
5.      Change into the ~/OneDrive/code/example.com/git
6.      python3.8 manage.py runserver 0:8000
7.      Load the site in your browser
8.      http://192.168.0.12:8000/
9.      Modify the project/pages/views.py in order to create a view that catches all the error pages. You may like to name a number of different pages individual action names that do various things on the server side, but to start this is how you have use a catch all. Simply add the following:
a.      from django.shortcuts import redirect
b.      def catch_redirect(request, *args, **kwargs):
c.         return redirect('index')
10.   Modify the project/project/urls.py and add the following including handler403:
a.      from django.conf.urls import handler400, handler403, handler404, handler500
b.      from pages import views as page_views
c.      urlpatterns = [
d.         path("", page_views.index, name="index"),
e.           …
f.      ]
g.      handler400 = page_views.catch_redirect
h.       handler403 = page_views.catch_redirect
i.       handler404 = page_views.catch_redirect
j.      handler500 = page_views.catch_redirect
11.   Voila! You now have handlers for the various error documents that may have come to be.
PS. You can see this is action on one of the sites I have started called inLoveLike. Check our this url: https://inlovelike.com/this-is-a-404-error-page.html
0 notes
debsdaniel03 · 4 years ago
Text
Tumblr media
☞ https://mailchi.mp/1fc9a9e05a5c/debs-8-cursos-oficial
🤑Un día para ahorrar| Cursos en los que confían millones de estudiantes desde solo 13,99 US$ | @udemy_es
🤜 #django #python3 #vuedj #javascript #jquery #vue #nodejs #postgresql y más
0 notes
debsdaniel03 · 5 years ago
Video
youtube
Espera en unas horas una #nueva #clasegratis  del curso #Desarrolla Aplicación de Compra y Facturación con #Python usando #Django en @udemy_es Veremos cómo podemos trabajar con la aplicación del curso usando Django 3 ¿Podrías Compartir el enlace? https://youtu.be/pxT9EUDKZyA
0 notes