PyCharm: Django templates don't seem to be working? - django

I am trying to use Django in PyCharm, but the Django templates are not working. For example {% block %} elements and {{variable}} references are not treated specially and when I view the page preview, it just displays it as text?

first go to pychram preferences :
select your project and chooce project structure and assign the values in the top to let pycharm what is you project structure:
from this page select Template languages:
select django

Related

How to make input box work in the result page

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.

Combining Django Templates and Polymer

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.

Joomla 2.5 pagination settings from administrator

I am beginner to joomla, currently using version 2.5. I have came across a problem with pagination. In my site pagination on all the pages were working well, but suddenly, I don't see any pagination for any page. I don't realized, what setting from admin panel I have changed. I have checked the settings from the Article Manger->options->Shared Options, but all are ok.
Is there any other settings in admin panel to show pagination?
Any help appreciated.
Thanks.
You must seach this in Article Manger->options->"First Tab"
But it can be also placed in the main menu item: Menu->MainMenu->"First item" general settings...
I have realize the problem, when I put <jdoc:include type="module" name="cblogin" /> in my template file, then all the pagination links get disappeared. I have also checked with putting below code -
jimport('joomla.application.module.helper');
$mods = JModuleHelper::getModules('cblogin');
echo JModuleHelper::renderModule($mods[0]);
but, nothing has changed. Is there any other solution to load module into html code?
If you want to add modules to articles, one way is to add a custom position to the article then assign the module to that position. In the article editor add this code
[loadposition myNewPosition]
Then you can assign any module to myNewPosition on the position option. Make sure the module is assigned to all pages.

django query db on every request

i have a navigation element that is determined by values in a database.
no matter what view it is, i need to get these navigation objects out of the database.
where in the code can i tell it to set a template variable containing all the navigation objeccts without setting it in every view?
It sounds like a good use for a context processor.
Right way to do this is to use templatetag. Then you don't have to include it in every view, just in your templates like {% load navigation %} {% navigation %}
How to write one:
django docs on template tags (read overview and inclusion tags)
anoher resource

Issue embedding TinyMCE in Django: the TinyMCE app wouldn’t show up in the browser

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