home / django_tickets / tickets

tickets: 5652

This data as json

id created changetime last_pulled_from_trac stage status component type severity version resolution summary description owner reporter keywords easy has_patch needs_better_patch needs_tests needs_docs ui_ux
5652 2007-10-01 16:21:35 2013-02-06 21:53:19 2022-03-06 03:35:00.925866 Accepted closed Core (Management commands) Bug Normal dev fixed Straightforward use of startproject command results in broken "Show on Site" link in admin If you use startproject in the straightforward way (such as following the Django tutorial), and if you as suggested implement get_absolute_url() methods in your models, you will indeed get "Show on Site" links in your admin interface. Unfortunately, they'll be broken because they will redirect to example.com. This is because the sites app is required, and thus activated; and it installs a default piece of SQL code that lists example.com as the URL for the project. Obviously, one possible fix is to document an additional step everyone has to do (go into their db interface and edit the sites table) to set up any straightforward app, however there are two downsides to that: the first one is it makes the tutorial more complex. However, the stronger reason is that it introduces an absolute URL when a relative URL would generally be a better choice anyway (for instance, my Django apps have different hosts when running under test versus in deployment; that's why a relative URL is the better solution in most cases). Fortunately, there's a simpler fix that seems to work just fine. Right now the settings.py file installed by startproject sets SITE_ID to 1. Per some earlier changelists, having this value set is required; but it's not required to set it to a valid site_id. If this setting is changed to any value that doesn't exist, the code in management handles the situation perfectly, and reverts to using the relative URL provided by the model's get_absolute_url method (almost certainly what everyone wants until/unless they're actually taking advantage of the sites application). Thus, the suggested fix is, in django/conf/settings.py, change the current uncommented line: SITE_ID = 1 to something like: # Right now, this is set to an invalid ID to show you're not using the sites app. SITE_ID = -1 Obviously not the most important bug in the world, but it's good to get all the little stumbling blocks out of the way of new users whenever we can! Leo nobody Leo Hourvitz <leovitch@gmail.com> SITE_ID 0 0 0 0 0 0
Powered by Datasette · Queries took 1.161ms