I'm following this tutorial about creating a simple blog with Django. I see that this guy has a lot of comments in his py-files with explanations and such. My py-files don't look at all the same. For example, in settings.py I don't have any varibale called TEMPLATE_DIRS, but in this guys file it looks like this:
TEMPLATE_DIRS = (
"",
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)
Since I'm a newbie I would of course appreciate the help that these comments and pre-defined variables provide. Why don't I have them? Have Django removed them in a later version?
Thanks in advance!
Perhaps the answer is here
Its because of your django version that you are using. in this tutorial they used django 1.3. its
existing in the django 1.3. But Its misssing in djang 1.4 and later versions.
So add the below code in your settings.py
from os.path import join
TEMPLATE_DIRS = (
join(BASE_DIR, 'templates'),
)
It may be that the author of the tutorial wrote his own comments so that readers would better understand each of the settings. It may also be that in a newer version of Django the core developers thought it would be simpler to leave them out of the default settings file created.
It doesn't matter much because each setting such as TEMPLATE_DIRS has a default value. So you can check django documentation for their meaning.
Related
This is a more-general question – just hoping to find someone who already knows.
("To save my forehead," y'know.) ;-)
I want to use CKEditor in conjunction with Machina forums, and I specifically want to be able to "drag and drop" images. I've found the right CKEditor feature to do that, but I'm getting "Incorrect Server Response" messages from CKEditor when I try to accomplish the drop. (This also happens on my development box.)
(Note that my concern is quite-particular to Django ("django-ckeditor"), and to the Machina forum software ("django-machina"). I need answers that are very tightly focused upon this use-case.)
So is there anyone out there who might say – "oh yeah, that happened to me, too, and the way to fix it is ...?"
Well, what do you know? I figured it out.
The problem was – and, as the django-ckeditor documentation clearly states, the default urlpattern entries (in the include file) specify a "staff-only" decorator for uploads. So, ckeditor was getting an error-message response and of course it didn't know what to do.
To solve the problem:
First, of course, be sure that ckeditor_uploader (as well as ckeditor) is installed on your system and is in your INSTALLED_APPS list in settings.py.
Now, in your urls.py, first add this line near the top:
from ckeditor_uploader import views as uploader_views
Next, insert the urlpattern entries that you find in the package's urls.py file, but referencing the uploader_viewsalias, viz:
url(r'^ckeditor/upload/',
uploader_views.upload, name='ckeditor_upload'),
url(r'^ckeditor/browse/',
never_cache(uploader_views.browse), name='ckeditor_browse'),
If you erroneously attempt to specify ckeditor_uploader.views. in the url() entry, you will be rewarded with:
NameError: name 'ckeditor_uploader' is not defined
Now you know! :-)
Also, don't forget what the Machina documentation told you to remember: ;-)
MACHINA_MARKUP_WIDGET = 'ckeditor_uploader.widgets.CKEditorUploadingWidget'
If you're doing "drag and drop," you're necessarily doing "file uploads," so you must use the provided field-types or (equivalently ...) the provided widgets from the ckeditor_uploader app.
After migrating project from Django 1.4 to 1.6 I've started to see a problem in the console:
/usr/lib/python2.6/dist-packages/django/utils/translation/__init__.py:63: DeprecationWarning: Translations in the project directory aren't supported anymore. Use the LOCALE_PATHS setting instead.
The message is of course pretty self-explanatory, but still would appreciate if someone can specify what has to be done to fix this.
To fix this, you have to define a LOCALE_PATHS tuple/list in your settings, as follows:
LOCALE_PATHS = ('/path/to/a/locale/directory/',) # the tuple can of course stay empty
As often, you just have to read the docs: LOCALE_PATHS
This link explains how Django performs the lookup for LOCALE files.
Usually I have the opposite problem, Django can't find the templates.
Lastly, I change a template of mine called custmber_view.html, but Django didn't notice the chagnes.
I tried flushing all caches, without success. In my dispair, I completely removed the template
hoping to see the familiar TemplateDoesNotExist exception.
To my surprise, Django keeps rendering the template! Although it is not found on the hard-drive.
Can someone suggest a solution to this mystery?
ARGH, legacy projects, I am doomed to fix them for ever. Somewise guy put the following in settings.py:
TEMPLATE_DIRS = (
os.path.join(project_dir, u'templates'),
u'/var/www/venv2.7/lib/python2.7/site-packages/backoffice/templates',
)
I feel like this now ...
So, conclusion, If you are working on a project which was not made as a Django App, always make sure you read the variable TEMPLATE_DIRS.
But for your colleagues future (and for better moral) always follow How to write reusable Django app
I'm using Django and I'm wondering whether it's proper to use myapp.models, opposed to myproject.myapp.models, or in INSTALLED_APPS, should the FULL NAME be used myproject.myapp or is it alright to just use myapp for it's name? I am wondering because if I were to change the project name using the latter method it would break my app, but I'm not sure that just because the former method works that it is correct. Could someone clear this up for me.
Thank you!
I would say that it is not encouraged to reference your apps using your project name. I say this because as of Django 1.4 this will not work with a default Django project. You can read more about this here:
https://docs.djangoproject.com/en/dev/releases/1.4/#updated-default-project-layout-and-manage-py
A quote from that:
"If settings, URLconfs and apps within the project are imported or referenced using the project name prefix (e.g. myproject.settings, ROOT_URLCONF = "myproject.urls", etc), the new manage.py will need to be moved one directory up, so it is outside the project package rather than adjacent to settings.py and urls.py."
I would recommend against it since it would mean messing with the default project structure, not a huge deal, but increased unnecessary work.
I would also recommend against it since it couples your apps to your project, which imho goes against the philosophy of Django which advocates reusable, decoupled apps.
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.