1st Blog
Published on April 1, 2026, 10:00
This first blog is created to use pure markdown generated in qownnotes where the files are held on self hosted ownCloud and then generated in HTML and presented from the django website using markdown2 and a model that reads the md file each time (no content held in the table).
The model, MdURL, that holds the URL generates markdown content on the fly and its the HTML text presented here. Django admin can view the content but not edit it.
New blog records created in qownnotes are managed via a watchdog command file in django that is run as a service on the server along with edits to existing blog items. Media inserts are handled in watchdog and copied with their URL to the /media within django.
As of writing the files are held in an app run on my Ubuntu PC and transfer to the main django server project will require several steps
TODO - migrate app to awsb.servebeer.com
- Create app on main server awsb.servebeer.com, settings, folders
- pip install markdown2
- adapt the URL in .env to server and oC [files at oC_blog, user blog see oC_blog]
-
- add service file, install/check watchdog
- adjust .env
- adjust settings, logging,
- makemigrations –fake, migrate –fake to keep data
The 2nd Blog will be about the progress.
Django model MdURL so that db table contains no content only ts, id, url, user, content is read each time accessed in the app.
class MdURL(models.Model):
created = models.DateTimeField(default=timezone.now)
title = models.CharField(max_length=100)
url = models.FilePathField(path="/home/ab/ownCloud/Notes/Blog", recursive=False, max_length=255)
user = models.ForeignKey('dmd.User', on_delete=models.CASCADE, related_name='url')
@property
def content(self):
"""Read content from the URL. Convert image path ../media to /media
image is copied to media path in watch_files at creation (edit ?)
"""
try:
with open(self.url, 'r', encoding='utf-8', errors='replace') as file:
al=file.readlines()
al2=al[2:] # skip title line and '===' underscores
html = markdown2.markdown("".join(al2), extras=[
"code-friendly",
"strike",
"fenced-code-blocks",
"tables",
"footnotes",
"toc",
"smarty-pants",
"highlightjs",
"linkify",
"wikilinks",
"abbr",
"deflist",
"sane_lists",
"citation",])
return html.replace('/media/', settings.MEDIA_URL)
# return markdown2.markdown("".join(al2), extras = [
except FileNotFoundError:
return "File not found."
except Exception as e:
return f"Error reading content: {e}"
class Meta:
verbose_name_plural = "Markdown URL"
permissions = [
("can_view_mdurl", "Can view MdURL"),
]
def __str__(self):
return self.title
Project Tree
Initially the project and app was setup in sqlite3 then migrated to mariadb in prep for transfer to main website, so table is blog
├── db.sqlite3
├── dmd
│ ├── admin.py
│ ├── asgi.py
│ ├── __init__.py
│ ├── management
│ ├── migrations
│ ├── models.py
│ ├── __pycache__
│ ├── settings.py
│ ├── templates
│ ├── urls.py
│ ├── views.py
│ └── wsgi.py
├── manage.py
└── ve_django5
├── bin
├── include
├── lib
├── lib64 -> lib
├── pyvenv.cfg
└── testing