I'd like to know if I can just ditch the Sites default app (comment it out from INSTALLED_APPS and so on) without breaking anything?
It's written in the doc that some other parts of django use it (redirects framework, comments, flatpages, syndic, auth, shortcut and view on site), but it's not explicitly said if it's going to break them. Is it?
Django 1.5
If you are sure that there are not any dependencies from some other files in your project or in your apps you can safely remove them.
First comment out one by one and every time check the project in your browser if it is running correctly. Also check the logs for warnings and errors.
Related
Long story short, I need to call a python script from a Celery worker using subprocess. This script interacts with a REST API. I would like to avoid hard-coding the URLs and django reverse seems like a nice way to do that.
Is there a way to use reverse outside of Django while avoiding the following error?
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
I would prefer something with low-overhead.
As documented
If you’re using components of Django “standalone” – for example,
writing a Python script which loads some Django templates and renders
them, or uses the ORM to fetch some data – there’s one more step
you’ll need in addition to configuring settings.
After you’ve either set DJANGO_SETTINGS_MODULE or called configure(),
you’ll need to call django.setup() to load your settings and populate
Django’s application registry.
I am using a custom manager command to boot my django app from external scripts. It is like smashing a screw with a hammer, but the setup is fast and it takes care for pretty much everything.
My site serves pages that are almost static and there are no users with logins etc.
I want to completely disable sessions for performance reasons (so django won't access the DB to get the session on every request).
I removed django.contrib.sessions from INSTALLED_APPS, is there anything else I need to do?
You should locate articles how to set up sessions in django and remove everything from settings.py according to such article. Here is it:
Although this should already be setup and working correctly, it’s
nevertheless good practice to learn which Django modules provide which
functionality. In the case of sessions, Django provides middleware
that implements session functionality.
To check that everything is in order, open your Django project’s
settings.py file. Within the file, locate the MIDDLEWARE_CLASSES
tuple. You should find the
django.contrib.sessions.middleware.SessionMiddleware module listed as
a string in the tuple - if you don’t, add it to the tuple now. It is
the SessionMiddleware middleware which enables the creation of unique
sessionid cookies.
The SessionMiddleware is designed to work flexibly with different ways
to store session information. There are many approaches that can be
taken - you could store everything in a file, in a database, or even
in a cache. The most straightforward approach is to use the
django.contrib.sessions application to store session information in a
Django model/database (specifically, the model
django.contrib.sessions.models.Session). To use this approach, you’ll
also need to make sure that django.contrib.sessions is in the
INSTALLED_APPS tuple of your Django project’s settings.py file. If you
add the application now, you’ll need to synchronise your database
using the python manage.py syncdb command to add the new tables to
your database.
So it seems that you should remove middleware too. Maybe it's not necessary, but if you're using static application, then you it's not that bad to remove everything according to the sessions.
I’m running a Django app on Heroku and have installed this piece of code: https://github.com/st4lk/django-solid-i18n-urls
It works just as expected on the Django built-in server, but when deployed to Heroku, I’m starting to see some really nasty problems.
I have Gunicorn running with multiple workers and if I use this code, the language preference starts to work randomly (I guess it depends which instance the request goes against).
For example if I have EN as the default (non-prefixed url) and DE as the second language, everything is working fine if I just browse the / urls. Now, if I switch to /de/ (manually enter URL or switch from the Django language switcher), the main / url starts to work intermittently – if I keep refreshing the page, I get either a 404 or the page in DE. But there’s no way to switch it back to using EN completely again. Same happens with all the other URLs as well, I get either a 404 or the corresponding page in DE. And there’s no way to force it back to EN, even from the Django’s set_language view.
If I never touch the /de/ urls, it works all very well without the prefixed URLs.
Does anyone have any ideas how to get this working also on Heroku and Gunicorn?
It turns out Gunicorn and the middleware override works fine, problem was with another piece of custom middleware.
I have Django project developed on Django 1.2, and I can't update it to newer version. I need add here an app, which developed on Django 1.4.
How can I start this as different projects on different versions and share user session in them?
How to setup correct url settings (ex. first must be /, second - /app)?
Take a look at this blog post on how to share users and sessions across two different projects. You will not require to match the session cookie domain since both your projects are already on the same domain.
Note: also read the comments, some important advice there in case you need help troubleshooting.
Re: URL settings - Obviously you cannot mount both projects on the same root. If project 1 is mounted on /, then you can mount the second project on /app. You can then configure project #2's URLs to use its root / (which is actually domain.com/app) directly for the new app's URLs. If you use /somethingelse for that app, your complete URL becomes /app/somethingelse.
I am in process to setting up a new django project and I want to use the provided apps django-registration and django-profile. I installed both of them with easy-install and managed to get the django-registration working fine. My next step would be to connect the django-profile app to the working branch. The django-registration offers a service, that redirects to a URL, which is defined in the settings.py-variable LOGIN_REDIRECT_URL. My guess was, that I can simply paste a url of the django-profile app to connect both. (e.g. '/profiles/').
My settings.py-variable AUTH_PROFILE_MODULE is set on 'registration.User', (trying to use the django-registration model!).
But I get a
SiteProfileNotAvailable at /profiles/
No exception supplied
error.
I tried to follow these steps:
https://bitbucket.org/ubernostrum/django-registration/src/tip/docs/index.rst
https://bitbucket.org/ubernostrum/django-profiles/src/tip/docs/overview.txt
But i am not sure, if I done everything properly, namely this paragraph from overview.txt
For default use, create a profile model for your site and specify the
AUTH_PROFILE_MODULE setting appropriately. Then add profiles
to your INSTALLED_APPS setting, create the appropriate templates
and set up the URLs. For convenience in linking to profiles, your
profile model should define a get_absolute_url() method which
routes to the view profiles.views.profile_detail, passing the
username.
So my questions are:
Is that a well known error?
Is it the right way to set 'registration.User' as AUTH_PROFILE_MODULE?
What is ment by "should define a get_absolute_url() method which
routes to the view profiles.views.profile_detail, passing the
username." in the overview.txt?
django-registration is hard to use thanks to the type of documentation and lack of templates. Many Django developers now use django-social-auth instead:
https://github.com/omab/django-social-auth
http://django-social-auth.readthedocs.org/en/latest/index.html
You can see how Kenneth Love integrated it into the Django Packages code base here:
https://github.com/opencomparison/opencomparison/blob/master/apps/profiles/views.py#L83
https://github.com/opencomparison/opencomparison/blob/master/settings.py#L277