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