Django Debug Toolbar Only Working for Admin Section - python

Hey,
I've been using Django 1.2.1 for some time now and came across Django Debug Toolbar just the other day. It looks really useful and I'm really eager to try some stuff out.
I installed exactly how the readme said. Step by Step. I put the middleware at the end just in case things get caught up but I'm using quite standard middleware (common, sessions, auth and csrf). However, it won't show up on any of my pages. I've tried moving the middleware but to the same effect.
It seems as if I've installed something wrong. But, when I load up the Admin Section of django, the toolbar springs up. I'm not sure what I'm doing wrong. Can the content of my pages effect the toolbar coming up? It's outputting in the mime text/html...
Anyway, any help is greatly appreciated. Thanks in advance.
Here's my Settings.py: pastebin.com/Hu8TgANt

Debug toolbar requires that there's at least a closing </body> tag in the response HTML.
This tag can be changed by changing settings.DEBUG_TOOLBAR_CONFIG['INSERT_BEFORE']
http://django-debug-toolbar.readthedocs.org/en/latest/configuration.html#toolbar-options

A few tipps without knowing your code:
'debug_toolbar.middleware.DebugToolbarMiddleware' should be your last or second to last middle ware entry (not 100% sure how it works out with the flatpagefallback middleware)
'debug-toolbar' as last in the list of INSTALLED_APPS
Double check if the toolbar's assets are loaded
Make sure all toolbar settings are set. (DEBUG_TOOLBAR_CONFIG, INTERNAL_IPS) etc.
The error should be something in there. I know of other problems related getting the toolbar displayed on flatpages so if you only checked on flatpages I suggest you try it on another module.

I had the same problem here, and eventually arrived at this post... Anyway, in my case what I noticed was that I had a javascript error in one of my js included libraries. And that breaked the js interpretation flow. When I fixed the javascript error, the django toolbar worked.
That explains why it worked in the admin pages, but not in my app pages.

Missing INTERNAL_IPS key in settings.py impacts toolbar visibility. Adding this resolves the issue:
INTERNAL_IPS = ('127.0.0.1',)

In my case, I was using Google Material Design Lite as the frontend framework,
which has the style definition,
*[hidden]{
display:none!important;
}
this style is applied to Debug Toolbar's elements which result in displaying nothing.
a quick workaround was to change the MDL's style definition (only possible on local stylesheets, not with cdn hosted) to
*[hidden]{
display:none;
}

I had a similar issue. The solution was closing a div as a non-empty HTML element.
From this
<body>
...
<div id="map-canvas"/>
...
</body>
to this
<body>
...
<div id="map-canvas"></div>
...
</body>
Hope it helps!

In my case the error was very simple.
I removed the footer and it worked like a charm!
Hope this solves an issue for somebody else.

Related

Django does not find static on all pages except the main

The project is hosted (support say to solve the problem yourself and therefore my friends hope for your help) and you can find it at: https://caparolcenterspb.ru
All styles, pictures and js appear on the main page, but not on other pages. You can see the errors directly in the browser, but just in case I give a screen:
It seems you are adding the path to the static file not from the STATIC_ROOT, but from the current URL. I'll explain with the example.
On the main page, you got the link:
https://caparolcenterspb.ru/
And looking for the static logo at:
https://caparolcenterspb.ru/static/img/Logo.svg
And all works fine. But if you will go to
https://caparolcenterspb.ru/services/
The URL for the logo request will change to:
https://caparolcenterspb.ru/services/static/img/Logo.svg
Which is wrong and there are obviously no files on this link.
So, the solution to your problem will be fixing STATIC_URL in Django settings. You need to use the same fixed STATIC_ROOT for all static requests and everything will be fine.
It is pretty simple, just check everything is done as it described here:
https://docs.djangoproject.com/en/3.0/howto/static-files/
The shown error explains your MIME is text/html not text/css. It's linked to your browser or OS.
Try to add this in your settings.py:
import mimetypes
mimetypes.add_type("text/css", ".css", True)

Ckeditor remains hidden after creation - editor.css is empty

I am trying to use ckeditor in a web project I am currently developing.
The problem is that when I try to instantiate the Ckeditor (either via the jQuery adapter or with the CKEDITOR.replace command), the editor is created but it is hidden.
I inspected the source code and for some reason it has this css attribute
.cke_skin_kama {
visibility: hidden;
}
Then I checked the css files that it uses and I noticed that the editor.css file has no css rule in it! It's completely empty, although it points to the correct url.
Do you know why this is happening? Any hint would be more than welcome!
Thanks in advance!
UPDATE: I tried to use Tinymce also, but I have the same problem. The file ui.css is empty too.
I am using python-webapp2 for GAE. Could this have any relation to the problem? Any specific configuration I have to do?
Thanks!
The problem probably lies in the declaration of your static files directories. Try to move ckeditor outside the paths of your existing static files. For example add the following in your app.yaml, and of course place the ckeditor in the respective folder:
- url: /ckeditor
 static_dir: static/ckeditor
if you want create chkeditor into your page you can use this code after attaching chkeditor javascript file :
<textarea id='chkeditor2' class='ckeditor' name='editor1'></textarea>
class and name is defined into javascript file and this text area will chkeditor panel. sorry for bad english :) i hope this will helpfull for you :)

Determine if website developed with Django [duplicate]

This question already has answers here:
How can you tell if a site has been made with Django?
(7 answers)
Closed last year.
I actually have some questions (real childish).
1) If I know that a website has been developed using django , can we determine from the html source code (by right clicking and choosing "view page source ") , if that website has been developed using django?
2) If I have an HTML code for website written in HTML , and I just want to present it like that using django , how can present this HTML code using django?
3) For what kind of websites , should django be used or are used for ? I mean pure static page , blogs , or a simple google like .
Thanks in advance
Here are a few things you could use to determine if a web app was written in Django. None of these are foolproof by any means, but they could be indicators.
Try http://site.com/admin/ and see if it says "Django site admin" at the top.
Inspect all of the HTML source code of every form you can find on the site, and see if any contain an input tag with name='csrfmiddlewaretoken'. csrfmiddlewaretoken is Django's CSRF token identifier. Other web frameworks may use this same name, but Django is the predominant user of it.
Find information about the site owner and/or developer from a "Contact" page, Google their usernames/emails as well as the word "Django," such as "emailname#gmail.com django". If you see posts or questions about Django, this could possibly mean they use it often.
If all else fails, simply contact the site owner and ask them.
No, the source depends completely on the person who developed it, and there are no necessary "hints" that it was written in Django.
You should at least try the Django tutorial at https://www.djangoproject.com/, you'll learn the basics of setting up a Django application, and you'll answer your own question.
Django is pretty general purpose, a bit overkill for static pages. Anything else can be done in Django, the same way it can be done in Ruby on Rails or other Web frameworks.
Well, what you should do is to test the website behaviour in an unusal stiatuation, for example forcing it to return 404 or 500 error message, which developers often forget to customize.
If you for example go to http://www.galaxyzoo.org/ and then try to determine backend just by looking at HTML, you'll fail.
If, however, you try to access a page 'blablablabla' i.e. http://www.galaxyzoo.org/blablablabla then you'll see 404 message. If you paste the entrie text into google, you'll most likely get hits to Ruby On Rails... :)
Django leaves no trace on the html source unless you specifically do. If you only want a static site, django is overkill. Though if you really want to, have a look at django flatpages.
You could possibly try www.domainname.com/admin. Some people leave their admin at that url and you can see the login page.
If they left the login page as default, the title tag will say Login | Django site admin or something like that.
For example: http://www.snowbird.com/admin/ (no affiliation)
No.
Yes. See direct_to_template
See djangosites.org

Unable to get URL-based context in django-template-repl

I'm trying out django-template-repl for debugging a template issue and it's pretty awesome.
One of the features of the tool is that you can go:
python manage.py templateshell -u /admin/
and pull up the context for that url location.
Unfortunately no matter what configuration of /admin/ or other urls in my site I try to pull up, I always get
/Library/Python/2.6/site-packages/template_repl/utils.py(11)pdb_with_context()->None
I am running it with the optional --pdb flag to see if I'm getting context in. And oh, my tab completion doesn't work either. :(
Any ideas on what I'm doing wrong? Thanks in advance
Finally got around to trying the solution codysoyland put up in the comments section. Sure enough, you need to have ipdb installed for this functionality to work. Now it works great.

Django: Page doesn't load images

I am working on a Django project for a company. This project worked very well before today.
Today I found a page can not show images (and their corrsponding links). I checked source code of THAT PAGE, I found there are images and links, I just can not find them on the page.
I checked the auth of the server and I am sure I can write things to the database. In fact, I think it is not database mistake because I can find what I want in the page source code, I just can not find them on the page.
Oh my Gosh, I am going to be crazy...
Has anyone suffered similar problem? What kind of problem could it be?
Please help me! Thank you very much!
PS: I can not provide any source code of the project because some business limit...I am really sorry...
Try exploring the site_media directory. If you're images are being served up as static content it could be related to the permissions of that folder on local disk or based on the settings.
Within your urls you may have something similar to:
(r'^site_media/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': '/path/to/media'}),
OR it may reference the path in the settings file something similar to:
STATIC_DOC_ROOT = '/path/to/media'
If the link looks correct for the image, but the side is not rendering the image even directly your issue will be somewhere in these areas.
For more information check the django docs:
http://docs.djangoproject.com/en/dev/howto/static-files/

Categories