The goal of efficiency is more slack.

Tuesday, September 17, 2019

Sites for Django

How to use the Sites package for Django.

Follow instructions in documentation to install the Sites package. Then create a migration in one of your apps.

from __future__ import unicode_literals

from django.db import migrations

def set_site_name(apps, schema_editor):
    Site = apps.get_model('sites', 'site')
    try:
        site = Site.objects.get(id=1)
    except Site.DoesNotExist:
        site = Site()
    site.name = "Astrobiology"
    site.domain = "astrobiology.nasa.gov"
    site.save()

class Migration(migrations.Migration):

    dependencies = [
        ('sites', '0002_alter_domain_unique'),
    ]

    operations = [
        migrations.RunPython(set_site_name),
    ]


Enter the latest migration from the "sites" app as a dependency to ensure there is a database table for sites.

On the development computer, run ./manage shell and change the domain of the site object to 127.0.0.1:8000.

Related Posts:

  • Install Django on a development MacNotes on installing a Django development environment on a Mac. Install Python Install Python 3 from www.python.org. Run Install Cerltificates.comm… Read More
  • Sites for DjangoHow to use the Sites package for Django. Follow instructions in documentation to install the Sites package. Then create a migration in one of your ap… Read More
  • Create a new Django project in VSCode Go to user settings (cmd-,): "python.venvPath": "~/.virtualenvs", Quit VSCode. Open a Python file in VSCode. Select virtualenv in bottom ba… Read More
  • Django in a subdirectoryHow to serve a Django project as a subdirectory of another Django project's URL. For example, the first Django site is at www.example.com/ and the sec… Read More
  • FeinCMS installationFollowing directions at https://feincms-django-cms.readthedocs.io/en/stable/installation.html, I ran into some problems, probably due to a Django vers… Read More

0 comments:

Popular Posts

Recent Posts

Unordered List

Text Widget

Pages

Powered by Blogger.
Scroll To Top