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.
Related
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.
I am using django.views.i18n.set_language() redirect view and HTML form where user can choose language.
I am doing everything as it's described in Django documentation for i18n translation .
The only difference that I made is that within HTML form I changed value of next parameter from {{redirect_to}} to {{request.get_full_path}}
Anyway, It worked completely fine while I was testing it locally. I could select different language and it would reload current page but with different language.
Now I put application on VPS where I use Gunicorn as application server and Nginx as web server. Now when I select different language it still changes it but it always redirect me to to home page / (site root).
I have no idea why is that happening now and how to change it. I want that he reloads the same page again instead of redirecting me to the / always. Anyway, at translation still works fine.
Thank you for your replys
Kind regards
Wander Nauta answered it in the comments
Are you sure request.get_full_path is available in the template?
You need to add django.core.context_processors.request in your template context processors settings, which is not there by default.
Today I was just in the train and had some spare time to think about django cms and admin.
Can I define pages as models like this:
class ArticlePage(models.Model):
slug = models.TextField()
content = models.TextField()
online = models.BooleanField()
etc...
and then edit this model in django admin? Because, i think, django cms will also work,more or less, in this way, right?
will this be fine?
Where i am stuck is that i dont know how to set dynamic urls for those pages, because i need to touch urls.py for this, right?
Theoretically you can create a view which has a wildcard as the URL. And then have the view lookup the various actually used URLs in the ArticlePage.
def pageView(request, url):
page = ArticlePage.objects.get(slug=url)
...
return page.content
With the URLs specified as:
urlpatterns += patterns('articles.views',
(r'^(?P<url>.+?)/$', 'pageView'),
) #Catch all URLs not yet matched and attempt to find them in the database.
at the end of your urls.py.
And then you can use an HTML editor of some sort to create the actual content and whatnot.
So it is possible. However the question is do you want to?
It is possible to create a few of the pages on a website completely from scratch and storing the HTML in a database. Think small pages which are rarely updated but if updated change rigorously.
However, generally speaking a website has some structure. Something like blog posts, comments, polls, user registration and other interactive pages. Those pages cannot be described in a database field holding HTML.
Although if you do actually manage to do all that then I fear for your sanity because it must have been a painful and awkward road.
Hope this helps.
Update:
If you want to show a static HTML only page you normally just refer to them directly from the urls.py. Generally very few HTML is directly stored in databases. Most often you just store data in the database. If HTML is heavily being modified/saved/created/served from the CMS you just store it as an HTML file somewhere on the webserver.
Although one can certainly think of reasons to put HTML pages in the Database there is an equal many reasons as to why you shouldn't. It all comes down to the specifics of the problem.
E.g. if you allow a user to create a comment with links/boldface/italics etc. you can save the word or //word// in the db and parse it every time. Or you can parse it once and just store the HTML in the database so you don't have to parse it every time.
Same goes for larger pages although they generally have too much markup to be hand typed via the CMS every so often.
As for serving an HTML page directly via urls.py:
E.g.
from django.views.generic import TemplateView
urlpatterns = patterns('',
(r'^foo/$', TemplateView.as_view(template_name='foo.html')),
)
Source: How do I go straight to template, in Django's urls.py?
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.