Sorry up front if my terminology will be non-standard, but I am new to Django and Python...I am using Python 2.7.3 and Django 1.4.3 on a Mac OSX 10.7 (Lion). Django-autocomplete-light version 1.1.7.
I am using the django-autocomplete-light module to create a page where I can search within a set of videos (hosted on an external source like Youtube). I defined a model / app called Videos that contains a set of videos hosted on this third-party site. At the top of my videos/index.html page, I have a search box that is powered by the django-autocomplete-light module. I have gotten the overall search function working--when I type something into the search box, the relevant videos are shown in the drop-down menu automatically. I want the clicked video to play within an embedded player on the page--for some reason, this keeps on loading the video into the entire, existing document / page instead of just the iFrame. In my structure for the search box, I included the "target" attribute already. My understanding is that including "target" should work, but I must be missing something. When I check Firebug, the "target" attribute is included in the link in the search results (sorry, can't post a screenshot of this since I don't have enough reputation points...but it's there. The iFrame also has its "name" attribute assigned to the same thing).
Side note--I am hosting the video on a private service (not Youtube), so I prefer not to use a library like jQuery TubePlayer...but the concept remains the same).
My questions--is there another way to do this? Am I missing something obvious? Does django-autocomplete-light not play nice with iFrames?
(templates/videos/index.html)
<iframe name="tvplayer" width="560" height="315" src="http://www.youtube.com/embed/CE0Q904gtMI" frameborder="0" allowfullscreen></iframe>
(navigation_autocomplete/autocomplete.html)--I understand that all videos will return the same link using this code, but I can't even get this one to work!
{% for video in videos %}
<a style="display:block" href="http://www.youtube.com/embed/3svKWr9LH4I" target="tvplayer">{{ video.title }} - {{ video.desc }}</a>
{% endfor %}
Thanks for your help!
Solved my own question...within the navigation_autocomplete/script.html page, you have to change the navigation_autocomplete javascript handler directly since it overrides any other styling / parameters that you put into the a tag.
Related
I am learning Django and i learn on making small project for lEARNING PURPOSE.
I learned how work with input and use as variable. Now i want to use search box with the same principle.
Please see the link of input based :
https://stackoverflow.com/questions/58813945/changing-form-to-search-box
index.html is the input after inserting info and clicking ok it directs to index2.html which shows the results
What I need to change besides POST to GET to make it work as it works with input function? do i need to change form, models?
My concern also i want to inset search bar in the navigation in index2.html where user can make search from the result page. This is my index2.html page. I tried to put {{form.as_p }} inside the form function but it does not work. I want after putting infro in search box and clicking search glyphicon (which does not work) will stay on the same page index2.html
I searched the internet and read stackoverflow other examples, but they use complicated version, i need a simple one :
1. i want to have search box on index.html page so it does not show me the name in front of input box and
2. i want search box in the index2.html page keep implementing the same function as index.html so a user do not have to go the initial page to search new data.
Any help or tips would be highly appreciated.
Since you're using bootstrap4 I would recommend to use its template tags and form field customization options.
Example:
{% bootstrap_field form.login show_label=False addon_before='<span class="fa fa-user"></span>' %}
Not: this example uses Font Aweseome for icons.
Also you're not using the real power of Django Bootstrap4, see Quickstart. You can always override the version of Booststrap or the CDN used in your settings.py if needed: Settings.
Currently I am Working on a workflow where on the left side are input fields and on the right half is a scalable pdf.
But actually I am not able to show a PDF in an iframe.
I am using django 2.1.1(python 3.7.2) on windows.
Is there any solution to display a pdf in an iframe?
I hope you have some ideas..i looked up many sides an tried different solution but actually the pdf document is not shown..
Hope to hear from you soon!
Kind regards
I have experienced a similar setting where I wanted to render a PDF in a webpage.
For that, I did the following :
Wrote a view method (in views.py) that renders the pdf's name. Indicated in the urls.py the path used for the view method. Next, in the HTML file, I use the following line of code :
<iframe id="iframe_pdf" src="{{ doc_file.url }}"
style="width:800px; height:800px;" frameborder="0"></iframe>
The {{ doc_file.url }} is the data obtained from the View method, it returns the PDF file location as a string. In my case, the pdfs were stored in the MEDIA_ROOT directory set in settings.py.
I've been stuck for the past few hours trying to figure out why the core Polymer elements are not being displayed properly in a Django application I'm making to act as a personal webpage. The application at the moment just points to an index.html page which, if you follow the tutorial on Polymer, is up to step one.
However, the components are not loading on my page. The static files are all set up correctly, and there's subtle animation from the css files being loaded correctly, but the Roboto font and the core-elements are not being displayed. Running the site as a normal HTML file does everything correctly.
Is there a specific way to user Polymer in a Django template?
Thanks.
See Eric's answer to this on the polymer-dev mailing list: https://groups.google.com/forum/?fromgroups=#!searchin/polymer-dev/django/polymer-dev/N2R8qknalOI/58ZhC1gWFh4J
Relevant excerpt:
Django 1.5 has support for the verbatim tag. You can wrap your inlined element definitions in that:
https://docs.djangoproject.com/en/1.5/ref/templates/builtins/#verbatim
Example code snippet:
{% verbatim %}
<template repeat="{{item as items}}">
<my-element name="{{item.name}}"></my-element>
</template>
{% endverbatim %}
<script>
document.querySelector("template').model = {{items}}; // items here is filled by the server's template.
</script>
I'm pretty sure this has to do with the fact that Django uses the same {{}} in its templates as Polymer.
I'm adding this answer as a compliment to the already accepted answer.
You can force django to require a space for it's template tags. So for any django template tags you have to use {{ variable }} and for polymer you will use {{variable}}.
Here is a very simple module/app I created to "prepare" django for use alongside polymer.
https://github.com/andrewebdev/django-ostinato/blob/2c435dea23319be6e9011e7381afca2b4092b5a2/ostinato/polyprep/init.py
Credit goes to https://github.com/nebrybledu for this suggestion.
I have a Django-powered page running on Apache with mod_wsgi. It works just fine in Firefox. When I switch to Internet Explorer, however, none of my links work. They all drop the domain part of the link.
For example, in Firefox, if I mouse over one of my links, I see something like this:
http://mydomain.edu/pathtomystuff/linkpage/
and it works.
However, in Internet Explorer, the same link shows this when I mouse over it:
http:///pathtomystuff/linkpage/
and obviously doesn't work.
If I manually type the address in Internet Explorer, it works fine. It's just the links.
This is probably something obvious and boneheaded. Please forgive me :)
UPDATE
Well I did figure out something of a "solution". I had BASE href= {{request.path}} in my base html file (which all other pages in my site extend). In reviewing the source code shown by IE and Firefox, both were seeing BASE href= which means request.path was not being passed to my template. So I changed it to BASE href=mydomain.edu and it works in IE now.
This is not a great fix though because it takes away from the portability of the django app...
If you want to preserve portability (as well as maintainability), the easiest and most "djangonistic" way to proceed would be to use {% url %} tags in your templates.
Note that the {% url %} tag should be passed a view as 'argument', for example: {% url myApp.views.myView foo='bar' %} will use your urlconf to create the appropriate url that will point to the myApp view called myView, with the value 'bar' passed as the 'foo' arg.
Of course, you needn't have arguments in all your views, the foo='bar' part is purely optional (Please do note that you shouldn't specify the request argument)
The most common use would be to use a syntax such as:
MyLink
Basically what you're trying to do here is reinvent the url tag, it already exists, so use it! :)
I’m working on a web application with Django, and I’m using the Flatpages app.
Now, I’m trying to embed the TinyMCE WYSIWYG editor in Flatpages. I’m following the steps mentioned in the Apress book: Practical Django Projects. And I’ve done everything right, but the TinyMCE app wouldn’t show up in the browser. When I asked the Django IRC channel we found out that it’s not a Django problem, the problem seems to be with TinyMCE itself. When I tried to look up the documentation at the TinyMCE website, all I found was either very outdated, or totally unrelated to my problem. How should I go about this?
Have you tried django-tinymce?
I had the django app but have ditched it in favour of:
http://code.djangoproject.com/wiki/AddWYSIWYGEditor
The instructions were simple and easy to follow - especially the flatpage bit.
The only real issue I had was having to set MEDIA_URL as a relative value. Until I did that - all my pop-up windows for links and html etc were blank!
Author James Bennett has put up the source code for Second Edition of the book so you can either: check your code against that, or simply download and use his code.
However, there are two specific questions that you need to answer before further help:
which version of the book? (Second Edition covers Django 1.1, i.e. from trunk)
which version of Django are you using?
which version of python do you have (python -V)?
If you're using the Second Edition and have svn'd Django from trunk, I can help - I have it working fine. Here's my (OS X) setup (just for working through the Second Edition of the book with Django from trunk):
in settings.py:
TEMPLATE_DIRS = (
'/Users/[myhome]/Sites/django-templates/cms/',
)
in urls.py:
(r'^tiny_mce/(?P<path>.*)$', 'django.views.static.serve',
{ 'document_root': '/Users/[myhome]/djangocode/cms/jscripts/tiny_mce/' }),
Then there's the copy of change_form.html duplicated from the django directory and copied to:
/django-templates/cms/admin/flatpages/flatpage/
which includes:
{{ media }}
<script type="text/javascript" src="/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript">
tinyMCE.init({
mode: "textareas",
theme: "simple" //or use advanced
});
</script>
{% endblock %}
Have a look through that and let us know how you get on!
I've been following the Practical Django Projects book myself. I got the TinyMCE embedded a few days ago as well. I can help, but I need a bit more info. Show me the line on the template where you include the TinyMCE javascript file. Also, describe where you placed the TinyMCE folder. I'm pretty sure your problem is that the script include reference doesn't match with the actual directory location.
A useful first check with JavaScript problems is to make sure all scripts are loaded. Take a look at the HTML source of the generated page in the browser, find all <script src="..."> tags and check that their paths are accessible.
You could also look at the terminal where you run the Django development server, or the "Net" tab of Firebug.
You can view the change_form.html code, which resides in my /[path to templates]/[project name]/admin/flatpages/flatpage/ and it works like a charm:
http://pastebin.com/f21a1cd97