django: default template file path? - django

Somebody told me all django apps automatically look within the root apps directory for a 'templates' dir first before looking within settings.TEMPATE_DIRS. However, this didn't work for me.
Is this not true?
I'm on django 1.3.1.
edit:
It turns out, the reason why it wasn't working inside my app's url mapping, I use a view from django.contrib.auth.views.login so it was looking inside the app dir for auth. A possible solution is to inherit login, but is there a better way to resolve this so django will look inside my app dir?

It's the other way around. By default Django first looks in settings.TEMPLATE_DIRS, and the in app folders. This can be customized by settings.TEMPLATE_LOADERS. which default to :
('django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader')
Details here: https://docs.djangoproject.com/en/1.4/ref/templates/api/#loader-types
But why would you want to do this?

Related

Can we custom whole Django Admin site is it possible?

Is it possible to do anything in the django-admin site? I mean can we custom it according to our needs??
django-admin is an application added to the default django projects. As you can see in settings.py file, there's 'django.contrib.admin' and 'django.contrib.auth' (which contains user management models and logics) in the INSTALLED_APPS array. You can get rid of them if you want and add your-own developed alternative apps instead. But django-admin is a powerful tool and there's many guides to custom it's functionalities. For example django admin cookbook is a famous one.
It's all dependent on what you want and need to do.
Yes of course, you can start copying whole /your_python_directory/site-packages/django/contrib/admin/templates/admin to your local template directory. (defined in your settings.py)

How to change 'Django Administration' name to a custom name in admin login and admin page

I am trying to change the name of django administration to custom name how do i do that.Is there any way completely customize the admin page give it more professional look
There are several ways to customize the Django admin.
First of all, you can always override any template (see docs : https://docs.djangoproject.com/en/1.6/intro/tutorial02/#customize-the-admin-look-and-feel it is actually using this very case as example)
Starting with Django 1.7, it will be accessible via settings : https://docs.djangoproject.com/en/dev/ref/contrib/admin/#adminsite-attributes
Finally, you could use a admin skin app such as the wonderful Grappelli wich already provides a similar setting : http://django-grappelli.readthedocs.org/en/latest/index.html
Hope this helps,
Regards,
Copy the admin templates to your project template folders (if you don't know how, just create an admin subdirectory in your project/templates folder).
The django branding is located in: base_site.html file.
You can find the source of it either in your django installed package or by checking the source code in github:
https://github.com/django/django/blob/stable/1.6.x/django/contrib/admin/templates/admin/base_site.html
Additionally with this method you can also completely override the default admin implementation, if you are not familiar or you don't want to spend so much time in it, you can also use a ready to use package such as grapelli: http://grappelliproject.com/ or django suit: http://djangosuit.com/
Note that branding will change in the next django release, the user will be able to define those in the settings file:
https://docs.djangoproject.com/en/dev/releases/1.7/#minor-features

How to use admin interface if I have no application?

I am creating a Django based app and I'd like to put everything under the root in the following structure:
/path/to/my/app/
settings.py
models.py
urls.py
admin.py
...
One problem that I run into is the admin interface doesn't include whatever models I have that are registerd in admin.py usin
admin.site.register(models.MyModel)
Usually that's done by using auto discover in urls.py, but now I have no registered "app", the auto discover doesn't work anymore. Is there anyway I can still use the admin interface?
Thanks.
Django simply doesn't work without apps. They're the fundamental building block of a Django site. A whole range of things, not just the admin, will fail to work. Why do you want to do this?
Putting the app in the django-style directory structure will make your project easily extensible if you decide to add functionality later.

Some basic questions about Django, Pyjamas and Clean URLs

I am farily new to the topic, but I am trying to combine both Django and Pyjamas. What would be the smart way to combine the two? I am not asking about communication, but rather about the logical part.
Should I just put all the Pyjamas generated JS in the base of the domain, say http://www.mysite.com/something and setup Django on a subdirectory, or even subdomain, so all the JSON calls will go for http://something.mysite.com/something ?
As far as I understand now in such combination theres not much point to create views in Django?
Is there some solution for clean urls in Pyjamas, or that should be solved on some other level? How? Is it a standard way to pass some arguments as GET parameteres in a clean url while calling a Pyjamas generated JS?
You should take a look at the good Django With Pyjamas Howto.
I've managed to get the following to work, but it's not ideal. Full disclosure: I haven't figured out how to use the django's template system to get stuff into the pyjamas UI elements, and I have not confirmed that this setup works with django's authentication system. The only thing I've confirmed is that this gets the pyjamas-generated page to show up. Here's what I did.
Put the main .html file generated by pyjamas in django's "templates" directory and serve it from your project the way you'd serve any other template.
Put everything else in django's "static" files directory.
Make the following changes to the main .html file generated by pyjamas: in the head section find the meta element with name="pygwt:module" and change the content="..." attribute to content="/static/..." where "/static/" is the static page URL path you've configured in django; in the body section find the script element with src="bootstrap.js" and replace the attribute with src="/static/bootstrap.js".
You need to make these edits manually each time you regenerate the files with pyjamas. There appears to be no way to tell pyjamas to use a specific URL prefix when generating together its output. Oh well, pyjamas' coolness makes up for a lot.
acid, I'm not sure this is as much an answer as you would hope but I've been looking for the same answers as you have.
As far as I can see the most practical way to do it is with an Apache server serving Pyjamas output and Django being used as simply a service API for JSONrpc calls and such.
On a side note I am starting to wonder if Django is even the best option for this considering using it simply for this feature is not utilizing most of it's functionality.
The issue so far as I have found with using Django to serve Pyjamas output as Django Views/Templates is that Pyjamas loads as such
Main html page loads "bootstrap.js" and depending on the browser used bootstrap.js will load the appropriate app page. Even if you appropriately setup the static file links using the Django templating language to reference and load "bootstrap.js", I can't seem to do the same for bootstrap.js referencing each individual app page.
This leaves me sad since I do so love the "cruftless URLS" feature of Django.

How do you setup admin media in Webfaction for Django?

I have my django setup. Now i just need to get the admin site to be correct. Currently there is no css asigned to it, so i guese my admin media urls etc in settings file is not correct?
Thanks
Have you read through their docs? Or is there something in there that wasn't working?
This seems more like a question to ask on their forum. Their tech people usually respond pretty quickly.
you need to issue
pythonX.Y manage.py collectstatic
where X.Y is the version of your application's python. this will copy admin media inside your static directory.