Consider the domain example.content.com. Now I want that content.com part to point to my django web application, and that example part to point to specific functions in my views.py folder, so that I can call different functions in my views.py by changing that example part. Is there any way to achieve this?
Any help is appreciated. Thankyou!
I think you want something like Subdomains!
I think django-subdomains package will be best for it!
Django Subdomain Docs
pip install django-subdomains
Related
I was following Django tutorial, and got stuck where it asked me to replace the default template for administrative part of the site with my own. The problem was a typo in the template's name. I suspected there must be a problem like that, but to troubleshoot the problem it'd be very helpful to see some kind of report from Django on what template it used to render a particular page. Is there any way to do this?
First if you have set DEBUG = True django automatically gives you information about where django was looking for templates (in general and especially in case it didn't find one)
You should see something like this:
second you can add the popular django plugin django-debug-toolbar. It can show you for each request what templates were used and what their context was.
see: https://django-debug-toolbar.readthedocs.io/en/stable/panels.html#template
Still, not exactly the answer, but something to get me closer. One could start Django shell, and then try this:
>>> from django.template.loader import get_template
>>> get_template('template/name').origin.name
to find out what template was actually used. This is still not enough to see though which templates were considered while resolving the template.
I am following the documentation and have already created my Permission instances so I can decorate my route functions, however, I have no idea how to hide links in the template. I saw an answer on here that used Roles but is there a way to use Permissions from Flask-Principal instead?
Hiding inaccessible links in Jinja2 templates The question asker's answer here sounds really good but would throw out my Permissions, also I don't really understand what he's doing, only that he doesn't have to re initialize the permissions/roles on the jinja2 template side.
My goal is to understand each flask extension's use as I learn. That's why I want to know if there's a way to do this without having to use Flask-Security or throwing out the Permissions I've already defined with Flask-Principal.
I use Flask-Nav with Flask-Bootstrap for creating navigation bar and I think you should follow its structure in your code as well. There are 2 basic steps:
Define a (multi dimensional) list of navigation links in your app code, where you can use all your Permissions during the process. Pass this filtered list to your template.
In your template loop over the list and generate a nice HTML code from it.
IMHO it is the right way to create a role- or permission-dependant navigation bar, because it separates the HTML-generating code from the "app" code.
I want to check the useragent using Django inside my template. I know this is possible using JavaScript, but I wanted a server side solution.
I know I can use HttpRequest.META in some middleware class, which I am not currently looking for. I want to determine this using some code in the template itself, without any dependency on other files / classes.
Can anybody help?
You need to use context processors, more specifically django.core.context_processors.request.
This SO answer covers it quiet well:
How can I pass data to any template from any view in Django?
Especially this blog post, that is referenced in the SO answer:
http://www.b-list.org/weblog/2006/jun/14/django-tips-template-context-processors/
This may seem quite a weird question but I'm quite confused right now and don't know what to do.
I'm working on an intranet web app using django. Soon I found that almost all features I need are done in django-admin, like adding and editing entries, view and filter items in a list view and so on. The missing parts can be done with some other additional views.
Should I just wrap up the admin app or should I re-implement the admin by myself? Or I should use something other than django like GWT or extJS?
That depends on your motivation. If this is an exercise in sharpening yourself then I suggest reinventing it. Mainly because you learn so much in the process. If the main goal is just to have the functionality then use the django-admin and bolt on whatever you need that it lacks.
I am trying to setup django-timezones but am unfamiliar on how to go about this. The only info that I have found is here: http://www.ohloh.net/p/django-timezones
class MyModel(Model):
timezone = TimeZoneField()
datetime = LocalizedDateTime('timezone')
I also tried looking through the pinax code or any other projects that use this app but haven't found anything.
Does anyone have an example or some info that they can share on how to use this?
Thanks,
Justin
Well, the firs thing you need to do when installing any Django app, is add it to your INSTALLED_APPS in settings.py. This particular app doesn't do to much other then give you some handy fields and things that you can use in other parts of your Django project. Your best bet to understand it is reading the source, I would say.