I'm working on my blog web using django. In my models.py I implemented RichtextField instead of the normal CharField or Textfield or others. I already imported it like this from ckeditor.fields import RichTextField after installing 'ckeditor' in 'INSTALLED_APPS in my projects settings.py.
Everything is working just Fine!
But there is problem!
The problem i'm facing is, I don't get to see the result of whatever I type in in my Django admin site using the RichTextField except plain text and some HTML tags in my localhost page.
What I mean is:
Supposing in my text-typing, I have something like this 'This is a bright new day...', and I want to bold 'bright' like this- 'bright'. I get to see it working perfectly in my django admin site. But when I refresh to my localhost page to where the text-typing is displayed, I get to see some weird HTML tag like this <b 'bright' /b> instead of 'bright'. And it did the same thing when I used summernotes.
So, please I will like to know why it's going that direction instead of the direction I want.
Secondly, the possibly solution to help me make move in the direction I want.
This same problem cut across to when I want implement codes, italics, headers, etc. in my whatever text I wish to change to those form.
Related
I've been able to easily create a list of editable items and manage them through the Django admin panel. That seems pretty simple and I have a good idea of how models work from other frameworks.
Although, I'm curious to know to know how I can make something as simple as editing a text area on a static site. Basically, I don't need to "add post" or anything of the sort. I just want to be able to edit a text area on a static site.
Any docs or examples?
I've been looking at packages such as django-flatblocks and chunks, these seem to possibly help with what I'd like to do. I'm just new to the Python world so some of this stuff is a little magic to me, especially involving the administration panel.
One thing that I realized is that these libraries (or apps in django?) seem to be super out of date, stemming back to the last commit being from 2012. Are these still commonly used?
Figured out a solution in case anyone is interested. I ended up using a Django application called django-generic-flatblocks which seems to provide me with what I need. Although, it's a bit strange as I had to replace all the text on my site with a gblock and then re-enter it all. Seems as if upon first creation of a block, it's empty so you essentially have to provide it with a value.
After that, if you log into the admin panel you're able to pull up the block and edit it. Alternatively, if you're logged into the Admin panel you're able to view your site and an edit tag is provided and you'll go directly to that block in the admin panel.
If anyone knows of anything which essentially allows me to define the text blocks up front in the admin panel then add the tags to the code, please lmk. I'd prefer to load all my content into the admin panel first and then just throw the tag into the code and have it display. That would save a lot of time in terms of having to copy the existing content, store it away, adding the tag, and then having to put it back in.
This seemed to be the only one of the recommended apps that worked for me. I tried to use Chunks because this really is only for title/text but on Django 1.11 it would freak out on me about not having South.db, which isn't even used.
https://github.com/bartTC/django-generic-flatblocks
I am using the TinyMCE editor for the admin part of my website. The editor seems like it is installed correctly but after saving a post and displaying it on the main page it shows the raw html instead of rendering it.
More specifically it shows
If it helps I used HTMLField in the model
when you want to display html stored in a model you need to mark it as safe (if it is of course) for it to bypass the XSS protection
see https://docs.djangoproject.com/en/1.10/ref/templates/builtins/#safe
Marks a string as not requiring further HTML escaping prior to output.
When autoescaping is off, this filter has no effect.
example for your template
{{ model.attribute|safe}}
I have an app that allows users (admins actually) to add html to a model. Then I serve that html on some page to other users (nonadmins). I would like to allow the admins to create arbitrary html on these pages, including adding images. I don't want the admins to have to jump through hoops to get their content into this html field. Suppose a user has some images on their local machine that they want to go into this html field they are creating. I want it to be super brain-dead easy for them to get those images in there.
Right now I just have a model with an html field and I provide a WYSIWYG editor . On a page that users can see, I just load that model.html (filter it as safe) and display. But if the admin user wants to add an image, they still have to figure out hosting and linking in their html document.
Is there a way to use Django flatpages + static to achieve this? Or some kind of app that provides a wordpress-like editor inside Django?
Honestly I would recommend just installing Mezzanine. It does exactly what you want and is the most lightweight, simple and Wordpress like of the Django CMSs. It integrates TinyMCE and Django filebrowser like you want and you can throw away the bits you don't want. This is almost definitely the quickest way to do what you want.
I'm working on a Django project, and I've created some custom admin views using the get_urls override method described in the documentation. It works perfectly. There is just one problem. There is no way to get to this custom admin view unless you already know the URL.
There are some ways I already know of to add a link to this view somewhere in the admin, but none of them are satisfactory. I want a link to the custom view to appear in the model listings right with all the model admins. I just don't want it to have +add or +change links next to it because it isn't a model.
I could just override the admin_site or the template, but this is no good. It puts the customization on the project level instead of the app level. It also will only put the link on the /admin/ page and not the /admin/myapp/ page.
I could also just easily add the link in a different location by overriding the app_index.html template, but that is not exactly a convenient or intuitive place to look for it.
Another solution I came up with is to create a blank model and register a blank admin for it. Then steal the url patterns for that model so clicking on its entry goes to my custom view instead of to a blank add/change view. That works, but it's an incredibly ugly hack.
Here is a picture of what I'm trying to achieve.
I still think the correct way of doing this is overwriting some parts of django admin templates. There is no easy way of adding these links.
https://docs.djangoproject.com/en/dev/ref/contrib/admin/#overriding-vs-replacing-an-admin-template
I also found this article http://coffeeonthekeyboard.com/o-hai-django-adminplus-568/ which also suggests that django-adminplus is a good tool for doing this. Personally I prefer to keep clear of any extra dependancies and would still use templates - but thats up to you.
Have you tried this app: https://github.com/jsocol/django-adminplus? Even if it does not work for the exact purpose you are trying to achieve, at least it can give you some enlightement by checking out the code
You need to override the template admin/index.html. Thenput a new pair of tags after the {% endfor %} on line 40.
You might also be able to solve it using jQuery.
I have a django app, and on the backend I've got a many to many field that I've set in the 'raw_id_fields' property in the ModelAdmin class. When running it locally, everything is fine, but when I test on the live site, the link to the lookup popout window doesnt work.
The django app resides at example.com/djangoapp/ and the admin is example.com/djangoapp/admin/
The links that the admin is generating for the lookup is example.com/admin/lookup_url/ rather tahn example.com/djangoapp/admin/lookup_url/
Any ideas why this is happening? Other links within the admin work fine, it just seems to be these raw id lookups.
Thanks for the help.
Edit:
In the source for the page when rendered, the breadcrumbs have the following:
<div class="breadcrumbs">
Home ›
This link works fine, going back to the root of the admin (example.com/djangoapp/admin/)
The HTML for the broken lookup link is:
<a href="../../../auth/user/?t=id" class="related-lookup" id="lookup_id_user" onclick="return showRelatedObjectLookupPopup(this);">
Looks like it might have something to do with the JS instead of the link itself.
This sounds like a bug in Django, I've seen a few of this kind. I'm pretty sure it has to do with the fact that you placed your admin at example.com/djangoapp/admin/ instead of example.com/admin/ which is the default. I have a hunch that if you change the admin url, it will work.