I'm using django-wysiwyg-redactor and I have two question
How can I send RedactorField input to the template as a field in the form?
I'm using django-modeltranslation as well, but in admin site other language fileds for redactor input is ordinary
TextField.screenshot How can I fix this?
I believe that there should be some easy ways for my problems. Thanks in advance
Use this FAQ https://imperavi.com/redactor/docs/how-to-install/.
To install Redactor, place the following code between the <head></head> tags:
<link rel="stylesheet" href="/js/redactor/redactor.css" />
<script src="/js/redactor/redactor.js"></script>
If your Redactor download is placed in a different folder, don't forget to change file's paths.
You can call Redactor using the following code:
<script type="text/javascript">
$(function()
{
$('#content').redactor();
});
</script>
Related
hey guys and girls :) hope you can help me :)
im trying to run brython but for some reason i just get
"uncaught ReferenceError: brython is not defined
at onload" . i did try it with local installation and i tried to use the CDN source files.
and on both i get the same result.
now basically i just copied from the documentation some simple sample just to get it work :)
i did brython-cli -update
and im currently running a 3.10.3 version
in local.
but even with the CDN import script it just didnt work
im rendering the html file through flask and running flask server(maybe its just that, have no idea).
<head>
<meta charset="utf-8">
<script type="text/javascript" src="brython.js"></script>
<script type="text/javascript" src="brython_stdlib.js"></script>
</head>
<body onload="brython()">
<h1>{{time_left}}</h1>
<script type="text/python">
from browser import document
document <= "Hello !"
</script>
</body>
I'm trying to add a standard datepicker (like air datepicker) to a standard bokeh text input.
I added the JS references and I'm linking a class in the text input field like:
event = TextInput(title=u"Event Date", value=' ', css_classes=['datepicker-here'])
In theory, that should work, yet, it is not...
I also tried with other standard datepicker, to no success.
Here is another case: flatpicker.
A simple datepicker which works perfectly with this setup:
Create a simple text input:
event = TextInput(title=u"event", css_classes=['flatpkr'])
and put the required js code in the template.
flatpicker examples here (how it should work):
$("input[type='text']").flatpickr({
enableTime: true,
dateFormat: "F, d Y H:i"
});
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/flatpickr/4.2.3/flatpickr.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/flatpickr/4.2.3/themes/dark.css">
</head>
<body>
<div>
<input type="text" placeholder="Please select Date Time">
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/flatpickr/4.2.3/flatpickr.js"></script>
</body>
If this is set in a plain webpage, everything is working properly. In Bokeh it does not, although I set exactly the same code in the template
{% extends base %}
{% block postamble %}
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/flatpickr/4.2.3/flatpickr.css">
{% endblock %}
{% block contents %}
{{ super() }}
<!-- JS Scripts -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<!-- Flatpicker -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/flatpickr/4.2.3/flatpickr.js"></script>
<script type="text/javascript">
flatpickr("input[type='text']", {
"minDate": new Date().fp_incr(1)
});
</script>
{% endblock %}
The extra information confirms what I thought you intended, but is not actually enough to run and investigate. That said, contrary to your supposition "In theory, that should work", I would actually never expect this to work. And the reason is that declaring a Bokeh TextInput does mean "just dump a bare <input> in the DOM". Rather, there is an entire JS implementation and CSS that Bokeh provides to support its version of a text input widget. In general, I have zero confidence that it would ever "just work" to have two different JS libraries fighting to control the same DOM element in their own separate ways.
If you want to do this sort of thing (i.e. integrate outside widgets seamlessly with Bokeh), it's possible, but the usual mechanism is by Extending Bokeh. In particular see the example Adding a Custom Widget. A custom extension will have a Python object that represents it and that is automatically synchronized the same as any other Bokeh object.
Another (simpler) possibility: You could put HTML (including your plain <input>) in a Bokeh Div. Bokeh won't try to style or control any DOM elements added inside a Div. That might reasonably be expected to work (though I have not tried). A widget added this way will not have a Python counterpart that it is automatically synced with, but its not clear what your actual requirements are, so that might be fine.
I'm totally a newbie to Django-Python.
So, whenever I include my tag like this,
<noscript>
<link rel="stylesheet" type='text/css' href="{% static 'homepage/css/style.css'%}" />
</noscript>
Browser doesn't take the code in noscript tag. Whereas, if I load that HTML file independently, there are no issues with the same browser.
Tried different ways,
<script>
var url = "{% static 'homepage/css/style' %}";
</script>
Didn't help though!
Please push me to pass through this bump!
Many thanks!
It's really all in the question but I'm using python-highcharts to build something like this jsfiddle example for inclusion in a Python Flask app. I can get it to work in the Jupyter notebook from where I can save it to an html file or export it as an iframe or div code block. But I can't get any of these to work in the flask html page. The inclusion block in the flask page looks like:
<p>
{% if result != None %}
<div id="my-chart"></div>
<script type="text/javascript">
{{result|safe}}
</script>
{% endif %}
</p>
and the relevant header parts:
<script src="//code.highcharts.com/stock/highstock.js"></script>
<script src="//code.highcharts.com/highcharts-more.js"></script>
<script src="//code.highcharts.com/modules/exporting.js"></script>
I've managed to get it working with pandas-highcharts but in this way I can't send tooltip formatting javascript functions via the dict-to-json-to-browser path... so a solution to either issue would be great.
J.
First off:
Writing JS functions in the HTML can (almost) always be prevented!
One of the first principles you should stick to is to separate your static files. More on that here.
You should only pass the variable into your script using Jinja2/DjangoTemplatingLanguage tags like this, and write all your javascript functionality in your separate .js file, which is then imported along with other scripts, by your example:
<script src="//code.highcharts.com/stock/highstock.js"></script>
<script src="//code.highcharts.com/highcharts-more.js"></script>
<script src="//code.highcharts.com/modules/exporting.js"></script>
<script src="{{ static_url }}/js/my-highstock-project.js"></script>
This way you have nice code separation and it is also (somewhat) more safe.
Which leads us to the problem at hand; importing...
So secondly:
HighCharts needs jQuery to be implemented before it can work. That is probably your problem.
To import jQuery include this to your header:
<script src="https://code.jquery.com/jquery-3.1.1.js"></script>
I wanted to use a third-party html/css example in Django, but it doesn't work.
<!DOCTYPE html>
<html>
<head>
<title>Example</title>
<link rel="stylesheet" type="text/css" href="/static/css/style.css" />
</head>
<body>
EXAMPLE CODE
</body>
</html>
I have used just this example, and commented all other code. Django recognizes the css file, I checked it. However, I don't get a sticky footer and header. They transform in a plain text, just like the main body.
I put this example in the codeacademy engine and it works there as well.
What hidden stones of Django I might be missing?
there is no hidden stones in django. there is no such option as recognize css file for django. Django has nothing to do with css files.
I recommend u to open network panel in browser developer tools console and check, was the css file downloaded successfully by browser or not.
in some case if u use django development server there is manual how to serve static files in development mode
https://docs.djangoproject.com/en/1.2/howto/static-files/
another cases are, misspelled css file name or misspelled/incorrect path to css file
https://docs.djangoproject.com/en/dev/howto/static-files/