easy-as-python / django-webmention Goto Github PK
View Code? Open in Web Editor NEW:speech_balloon: webmention for Django projects
Home Page: https://www.w3.org/TR/webmention/
License: MIT License
:speech_balloon: webmention for Django projects
Home Page: https://www.w3.org/TR/webmention/
License: MIT License
Currently there's no requirements.txt file for the project, which makes setting up the project challenging.
It would be great to have a little more documentation about what installing this does, and what else is required. I have a very rough idea of how webmentions work, but am very, very far from an expert, so forgive me if any of this is blindingly obvious to you... but I'm a bit stumped as to how to proceed.
Link: <https://example.org/webmention/receive>; rel="webmention"
. It should be mentioned that this is what happens. Does anything else happen?response_to
attribute that matches the URL of that page, pass them to the template and display them?Sorry if this is basic but having installed it I was a bit "Now what? Do I have to do anything else? Is it working? How can I tell?"
Using class based views I get the following error:
'MyPostDetailView' object has no attribute 'scheme'
In both the Admin list view and the create/edit view for Webmentions, the clickable links show as HTML rather than clickable links:
I guess they should be building the HTML using format_html()
, something like in this StackOverflow answer.
I don't know if the Response body in the create/edit view is supposed to be raw HTML like that - maybe it is; if so, that's fine :)
(Django 3.1)
Django: 1.10.8
Python: 3.6.3
With middleware enabled in settings.py, the following error occurs:
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x10ed9bea0>
Traceback (most recent call last):
File "/Users/tehfink/Documents/work/mylittlepony.net/www./source/3.0/mlp_website-virtualenv/lib/python3.6/site-packages/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "/Users/tehfink/Documents/work/mylittlepony.net/www./source/3.0/mlp_website-virtualenv/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 142, in inner_run
handler = self.get_handler(*args, **options)
File "/Users/tehfink/Documents/work/mylittlepony.net/www./source/3.0/mlp_website-virtualenv/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/runserver.py", line 27, in get_handler
handler = super(Command, self).get_handler(*args, **options)
File "/Users/tehfink/Documents/work/mylittlepony.net/www./source/3.0/mlp_website-virtualenv/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 64, in get_handler
return get_internal_wsgi_application()
File "/Users/tehfink/Documents/work/mylittlepony.net/www./source/3.0/mlp_website-virtualenv/lib/python3.6/site-packages/django/core/servers/basehttp.py", line 46, in get_internal_wsgi_application
return get_wsgi_application()
File "/Users/tehfink/Documents/work/mylittlepony.net/www./source/3.0/mlp_website-virtualenv/lib/python3.6/site-packages/django/core/wsgi.py", line 14, in get_wsgi_application
return WSGIHandler()
File "/Users/tehfink/Documents/work/mylittlepony.net/www./source/3.0/mlp_website-virtualenv/lib/python3.6/site-packages/django/core/handlers/wsgi.py", line 153, in __init__
self.load_middleware()
File "/Users/tehfink/Documents/work/mylittlepony.net/www./source/3.0/mlp_website-virtualenv/lib/python3.6/site-packages/django/core/handlers/base.py", line 82, in load_middleware
mw_instance = middleware(handler)
TypeError: object() takes no parameters
I noticed a subtle bug in the resolution.py::fetch_and_validate_source.
While response.content is a bytes-string ( docs), it's never decoded before saving to the database. As a result it saves as a string into the db as follows: "b'\n<!DOCTYPE html><html><head><meta charset="utf-8" />\n<...."
.
Practically speaking this is fine for pure ascii data, but any unicode characters aren't be properly decoded before saving, resulting in double-escaped characters and must be corrected before you can display it properly to the user. e.g. "Çelik"
will be saved as "\xc3\x87elik"
>>> b'\xc3\x87elik' # raw bytes from response.content
b'\xc3\x87elik'
>>> str(b'\xc3\x87elik') # raw string conversion gets double esacped
"b'\\xc3\\x87elik'"
>>> b'\xc3\x87elik'.decode("utf-8") # properly decoded
'Çelik'
Existing response_bodies can be fixed using ftfy package by running the string through something like this ftfy.fix_text(ftfy.fixes.decode_escapes(mention.response_body))
.
Changing fetch_and_validate_source to return response.text
, which is simply the decoded response.content would fix this issue. Looking for the target in str(response.content)
might also have a subtle bug if you used a utf-8 domain as well, so I believe it should validate using response.text as well.
Refactored I think it should look something like this:
def fetch_and_validate_source(source, target):
response = requests.get(source)
if response.status_code == 200:
if target in response.text:
return response.text
else:
raise TargetNotFoundError("Source URL did not contain target URL")
else:
raise SourceFetchError("Could not fetch source URL")
This project is currently still configured to use Travis CI, but is no longer hooked up to it. The preferred flow now uses GitHub Actions—an example can be seen in code companion for Publishing Python Packages.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.