question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to test sub-domains in my localhost?

See original GitHub issue

I set up django-subdomains following this [guide][1].

I set my subdomain urlconfs as follows:

    SUBDOMAIN_URLCONFS = {
         None: 'mysite.urls',
        'www': 'mysite.urls',
        'shop': 'mysite.urls.shop',
        'blog': 'mysite.urls.blog'
    }

Everything works nicely, but I can’t really test it cause when I run my app on my local host using python manage.py runserver, I can’t really add the subdomains. If go to http://blog.127.0.0.1:8000, then the browser says a server cannot be found. Is there any way to set my server in such a way that allows for testing?

I also have this following line in my console: No handlers could be found for logger “subdomains.middleware”

How can I get this working? If anyone wants, my settings.py file can be found here:

Pastebin Link

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:1
  • Comments:5

github_iconTop GitHub Comments

5reactions
abe312commented, Oct 31, 2016

python manage.py shell

 from django.contrib.sites.models import Site
 one = Site.objects.all()[0]
 one.domain = 'myveryspecialdomain.com'
 one.name = 'My Special Site Name'
 one.save()
 one.id() #save this id to SIDE_ID in settings.py

then you need to modify /etc/hosts file

sudo vim /etc/hosts
127.0.0.1       api.mysite.app
127.0.0.1       www.mysite.app
127.0.0.1       mysite.app

it should work

Note: django-subdomains doesn’t has support for django1.10. for that I have made a pull request… so django version should be under 1.9 for now 😃

3reactions
jamesh38commented, Oct 31, 2016

I did. Make sure you follow the directions on the docs. Adding the middleware before common. Then you must include Django.contrib.sites in your apps and then do run Python manage.py migrate. Finally the after adding the settings they provide in the docs to your settings file you’ll need to access the database and change the value of entry 1 in the “django_sites” table to reflect what local domain you have set up. So change “example.com” to “mysite.app” or whatever you use. This is the ticket. The subdomains will not recognize if you don’t have this site set and SITE = 1 in your settings.

I set this up like 4 times correctly since I posted this. So message me if you have any other problems.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Add subdomain to localhost URL - Stack Overflow
First navigate to /mnt/c/Windows/System32/drivers/etc (Navigate cause, you may find more interesting files. Don't play here, but see what do they do) · Then...
Read more >
Setting up subdomains on localhost - Server Fault
You need to set your /etc/hosts or C:\Windows\system32\drivers\etc\hosts (as administrator) to reflect the "subdomain".
Read more >
Subdomain error: localhost.com and subdomain-test ... - Drupal
Hi, I'm in need of a desperate help to resolve this sub domain error. My main domain and subdomain has different ip address...
Read more >
How to Set Up HTTPS and Subdomains on Localhost With ...
Learn how to use Caddy Server to set up SSL and subdomain support for your local development environment.
Read more >
Local Domain & Subdomain Testing in Mac & Linux - Blog Post
sudo nano /etc/hosts You should see something like: Copy ## # Host Database # # localhost is used to configure the loopback interface ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found