2 min read Author: admin

medium.py

A simple, medium like python blogging package.
Made for self hosting.

Medium like means that it mimics the style, UX, usabilty like inline editing ... Package means using the great stuff out there like mediumish theme from wowthemes. The wonderful medium-editor which gives you the capability to edit the articles inline. The backend is served by PythonOnWheels. The superb tinyDB is used as a small simple, local file based NoSQL python DB.

Actually this is a medium.py site.

You can login (user: admin/ pwd: nimda) and play around right now and edit this article online. Saving changes to this main article is protected in this online demo. Any blog article can fully be changed and overwritten....  

But can also easily host the package on your own system. And that's what it is actually ment for. Just clone and run. see below.

Simple usage:

git clone https://github.com/pythononwheels/medium.py.git medium

Install the requirements: (I reccomend making a virtualenv)

pip install -r requirements.txt

python server.py

Thats it!

You can see it in action right here actually this site is served by medium.py. It includes all the great tools and packages out there:

You can check out the repo on github:  ()

This is the article list / admin view


Some functions require a (local) login,

they will redirect you to a login form. Just login using the preconfigured user: (you can change that later on)

user/passwd: admin/nimda

So this is a first article.

I can do fancy stuff like lists:

  • one
  • two
  • Three

Images:

(That are automatically file uploaded (PUT) and linked) using the great medium-editor-insert-plugin


Code:

class myTest():
def myfunc(self, data):
return str(data+"stupid!")

Highlight.js is included.

Some more Headers

H2 Header

H3 Header

H4 Header

Bold important stuff

some italic to remember

And so on. Simply type and edit.... I think you got the point ;)

See medium-editor.js  for all editor functions. 

Below I just made some test copy&pasting code and using the custom buttons for python, javascript, code ...

Syntax highlighting 

Python: (Copy & Paste from VScode, then marked and clicked python button):

def pow_json_serializer(obj): 
"""JSON serializer for objects not serializable by default json code"""
if isinstance(obj, datetime):
#serial = obj.isoformat()
serial = obj.strftime(medium.config.myapp["date_format"])
return serial

Another Test with JS:

function replace_p_by_br( html, tag = "<span>"){ 
//
// cleans all <p></p> in a given html and replaces them by <br>
//
// create a pseudo element
var $dataWrapper = $(tag);
$dataWrapper.html(html)
// now we have the selected html inside a <tag>
$dataWrapper.find("p").each( function(){
var htmlInsideColumn = $(this).html();
var convertedHtml = htmlInsideColumn + " <br >";
$(this).after(convertedHtml); //let's place the converted html right after this column element.
$(this).detach();
});
// return the new html
return $dataWrapper.html();
}