0

I've two databases in my Django app, BUT with different IP's, ie HOST are different.

    'default': { # This is the DB in the same machine itself.
        'ENGINE': 'django.db.backends.postgresql_psycopg2', 
        'NAME': 'sortation_gor',              
        'USER': 'vms_gor',
        'PASSWORD': 'apj0702',
        'HOST': '127.0.0.1',
        'PORT': '',
    },
    'a1': { # This is in another machine with IP listed below.
        'ENGINE': 'django.db.backends.mysql', 
        'NAME': 'a1',              
        'USER': 'root',
        'PASSWORD': '',
        'HOST': '192.168.1.27',
        'PORT': '',
    }
}

When I run my code, and I try to save data in a1 DB, it returns me 500 error. But if I've the DB in the same machine in which the app is running, it works fine. What can be the problem?

Q2) In my templates, I've a check field that :-

{% if admin_permission %}
   <li id='main_menu_config'><a href="{% url 'configuration' %}"><span class="icon-cog icon-white"></span> Configuration</a></li
{% endif %}

Although the Configuration tab is not visible, but I can still navigate to the URL(provided I know the exact URL) even if I'm not admin.

How can this be solved.

Routers.py file

class GorRouter(object):
    """
    A router to control all database operations on models in the
    gor application.
    """
    def db_for_read(self, model, **hints):
        """
        Attempts to read gor models go to gor_db.
        """
        if model._meta.app_label == 'gor_data':
            return 'default'
        return None

    def db_for_write(self, model, **hints):
        """
        Attempts to write gor models go to gor_db.
        """
        if model._meta.app_label == 'gor_data':
            return 'default'
        return None

    def allow_relation(self, obj1, obj2, **hints):
        """
        Allow relations if a model in the gor app is involved.
        """
        if obj1._meta.app_label == 'gor_data' or \
           obj2._meta.app_label == 'gor_data':
           return True
        return None

    def allow_migrate(self, db, model):
        """
        Make sure the gor app only appears in the 'gor_db'
        database.
        """
        if db == 'default':
            return model._meta.app_label == 'gor_data'
        elif model._meta.app_label == 'gor_data':
            return False
        return None



class A1Router(object):
    def db_for_read(self, model, **hints):

        if model._meta.app_label == 'a1_data':
            return 'a1'
        return None

    def db_for_write(self, model, **hints):

        if model._meta.app_label == 'a1_data':
            return 'a1'
        return None

    def allow_relation(self, obj1, obj2, **hints):

        if obj1._meta.app_label == 'a1_data' or \
           obj2._meta.app_label == 'a1_data':
           return True
        return None

    def allow_migrate(self, db, model):
        """
        Make sure the aramex app only appears in the 'aramex_db'
        database.
        """
        if db == 'a1':
            return model._meta.app_label == 'a1_data'
        elif model._meta.app_label == 'a1_data':
            return False
        return None
Praful Bagai
  • 16,684
  • 50
  • 136
  • 267
  • 2
    Split your questions into two separate questions. They are unrelated and combining both here has a high likelihood of getting this questions closed as too broad. – Andy Jul 31 '14 at 05:25
  • Debug is already Enabled. All it returns is `500 Internal Server Error. Contact the Administrator.` – Praful Bagai Jul 31 '14 at 05:31
  • Can you paste your DatabaseRouter please? – Victor Castillo Torres Jul 31 '14 at 05:52
  • regarding the first question - have you tried connecting to the DB without django? i.e. open a shell and try connecting with it. If you succeed, it's a problem with django. If not, it's probably a problem with the host which might have some configuration preventing remote connections entirely – yuvi Jul 31 '14 at 06:31
  • Ohh...let me try that. – Praful Bagai Jul 31 '14 at 06:32

0 Answers0