Disable Django admin - django

I'm in a selection process and I must develop a software in Django with the restriction of not being able to use the admin included in the framework.
I tried removing it from the INSTALLED_APPS. But when I run a migration I get the error:
'No installed app with label 'admin'
Is there any other configuration that I should do or what is the correct way to do it?

Be sure to remove it from:
urls.py
remove from urlpatterns
remove the import statement
INSTALLED_APPS
That's it.

Related

Django TemplateDoesNotExist admin/login.html

I am working with django 1.4. And this error appeared:
TemplateDoesNotExist at /admin/
admin/login.html
I tried to reinstall django, but i did not work... Please Help!
You can try to add the admin tempates path name to TEMPLATES['DIRS'] in your django settings.py
The default TEMPLATES:
'DIRS': [os.path.join(BASE_DIR, 'templates')]
change to if you are using Django project created by Pycharm:
'DIRS': [os.path.join(BASE_DIR, 'templates'),
os.path.join(BASE_DIR, 'venv/lib/site-packages/django/contrib/admin/templates')]
Django by default looks for templates in each app having directory name "templates".
you can add your own path in settings.py file
Assuming that you are trying to use the default Django admin, be sure that 'django.contrib.admin' is in the INSTALLED_APPS section of your settings.py file.
I got that same error trying to use the default built-in login functionality.
My settings.py has the default settings, 'django.contrib.admin' is in the INSTALLED_APPS section of my settings.py file, as suggested by sean.
Elaborating on Tim's answer, I believe that we are refering to a missing template.
See the docs at https://docs.djangoproject.com/en/1.7/topics/auth/default/#django.contrib.auth.views.login:
"It’s your responsibility to provide the html for the login template, called registration/login.html by default."
Add your app name in INSTALLED_APPS list inside settings.py.
If you're getting a "TemplateDoesNotExist" error, that means you are referring to a template that does not exist. :) You should have a templates directory, and check to see if admin/login.html exists in that directory path.
This is the Django 1.4 template documentation. IMO the Django documentation is quite good compared to most stock documentation.
Also you should know that the admin interface is not really designed to be customized. The built-in admin interface has a login feature already built-in, if you create a superuser with the manage.py script. If you're trying to build your own template, you should do so separate from the admin interface, unless you disable/remove the built-in admin interface completely and design your own from scratch. Modifying built-in admin code is more trouble than it's worth in my opinion.

TemplateDoesNotExist login.html django1.4 [duplicate]

I am working with django 1.4. And this error appeared:
TemplateDoesNotExist at /admin/
admin/login.html
I tried to reinstall django, but i did not work... Please Help!
You can try to add the admin tempates path name to TEMPLATES['DIRS'] in your django settings.py
The default TEMPLATES:
'DIRS': [os.path.join(BASE_DIR, 'templates')]
change to if you are using Django project created by Pycharm:
'DIRS': [os.path.join(BASE_DIR, 'templates'),
os.path.join(BASE_DIR, 'venv/lib/site-packages/django/contrib/admin/templates')]
Django by default looks for templates in each app having directory name "templates".
you can add your own path in settings.py file
Assuming that you are trying to use the default Django admin, be sure that 'django.contrib.admin' is in the INSTALLED_APPS section of your settings.py file.
I got that same error trying to use the default built-in login functionality.
My settings.py has the default settings, 'django.contrib.admin' is in the INSTALLED_APPS section of my settings.py file, as suggested by sean.
Elaborating on Tim's answer, I believe that we are refering to a missing template.
See the docs at https://docs.djangoproject.com/en/1.7/topics/auth/default/#django.contrib.auth.views.login:
"It’s your responsibility to provide the html for the login template, called registration/login.html by default."
Add your app name in INSTALLED_APPS list inside settings.py.
If you're getting a "TemplateDoesNotExist" error, that means you are referring to a template that does not exist. :) You should have a templates directory, and check to see if admin/login.html exists in that directory path.
This is the Django 1.4 template documentation. IMO the Django documentation is quite good compared to most stock documentation.
Also you should know that the admin interface is not really designed to be customized. The built-in admin interface has a login feature already built-in, if you create a superuser with the manage.py script. If you're trying to build your own template, you should do so separate from the admin interface, unless you disable/remove the built-in admin interface completely and design your own from scratch. Modifying built-in admin code is more trouble than it's worth in my opinion.

django - how to disable apps

I have multiple settings_x.py
I want to disable app1 which is inside INSTALLED_APPS of one settings_1.py
I tried to comment the app, but the app is still avalaible from urls.py.
how can I do this? I dont want to delete, I just want to turn off the app.
in urls.py of project ,import settings of project.
from django.conf import settings
in urls.py of project, add this code.
if 'app1' in settings.INSTALLED_APPS:
urlpatterns += url(r'^app1/', include('app1.urls'), name='app1'),
if you add this code, system will check if the app is added to INSTALLED_APPS list in settings.py or not. If it does not exist, system will not add its urls.py configurations and also the urls of app will not work.
Apps are available even though they are not specified in settings.py. I can't imagine your case when you want to make the app unavailable from urls.py.
A solution to your problem can be using a version control system like git and using multiple branches. Delete the app in the branch where you don't need the app.

Django syncdb can't find my apps

I'm a django newbie and have been having a problem.
In my project root I created a folder called 'local_apps' and within it I put the app 'myapp'. I updated the INSTALLED_APPS within settings.py with: myproject.local_apps.myapp
However when I try to syncbd, Django gives an error: 'no module named local_apps.myapp exists'
When I put 'myapp' back in the project root, it works again but I dont want it that way. I want to keep my apps in the folder 'local_apps'.
Can you tell me what I am doing wrong here.
Thanks in advance.
I think that's a generic python error, not a Django error.
Maybe you need to create an __init__.py file in the local_apps directory, so python knows it's a module.
Do you have a models.py within the myapp folder? I think Django may need to see that file in the app.
[Edit: actually, I think wisty above may be right, make sure you have an __init__.py, if you do, try the models.py.]
I was facing the error: ImportError: No module named foo
To solve this, I just added the Django site package to the Python path at settings.py module like this:
PKG_DIR = os.path.dirname(__file__)
sys.path.append(PKG_DIR)

Django ImportError while adding guardian module

Being a beginner of using Django, i am trying to add some module for the purpose of testing Django, but I've got a problem regarding the importError which I've googled for solution with no success. Below is my situation
The project is created to my PC J:\ while the python package is installed on C:. According to guardian's installation guide following code have to be added in django's backend:
AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend', # default
'guardian.backends.ObjectPermissionBackend',)
The problem's come, when I put the guardian's app under the directory of mysite, configurate the install_apps setting with 'guardian' and start syncdb, the error claim as below which i believe that it is because the django's filw do not understand what is "guradian" really is
File "J:\mysite\guardian\conf\settings.py", line 6, in
raise ImproperlyConfigured("In order to use django-guardian's "
django.core.exceptions.ImproperlyConfigured: In order to use django-guardian's O
bjectPermissionBackend authorization backend you have to configure ANONYMOUS_USE
R_ID at your settings module
So, I move the 'guardian' folder under Django's contrib folder, adding the sys path and configurate the install_app setting with 'django.contrib.guardian'. However, I end up with the importerror.
As it seems from the error message, you need to add the user id for anonymous user for you site.
Create a user (named maybe anonymous) and put the id of user in the settings.py file.
Obtain the user id from the database using the shell.
Put the id in the settings file:
ANONYMOUS_USER_ID = <Your anonymous USER_ID>
EDIT:
Just looked through the documentation of the django-guardian app. It also specifies this:
http://packages.python.org/django-guardian/configuration.html