22👍
I prefer resetting admin.site.site_url
in urls.py
, along with other site changes (instead of doing this in an admin.py
file, cause a project can have serveral admin.py)
# urls.py
admin.site.site_url = '' # Removes the 'View Site' link
admin.site.site_header = 'My Site'
16👍
In Django 1.11.5, it seems that :
from django.contrib import admin
and
admin.site.site_url = 'https:....'
in the admin.py file is enough
- [Django]-PyCharm: Forcing Django Template Syntax Highligting
- [Django]-How to get GET request values in Django Templates?
- [Django]-Is there something similar to 'rake routes' in django?
11👍
By default , “VIEW SITE” points to ‘/’ i.e localhost:8000 (Default settings assumed).
To change it , use (in admin.py):
admin.site.site_url = "/mySite"
Tested on Django 2.1
- [Django]-Reporting yielded results of long-running Celery task
- [Django]-Django.db.utils.IntegrityError: NOT NULL constraint failed: products_product.image ERROR WITH IMAGE FIELD
- [Django]-Django allauth facebook redirects to signup when retrieved email matches an existing user's email?
5👍
There are two solutions I can come up with.
Firstly, you could use custom template admin/base.html
. But, reading through the default template, you would have to copy-paste a lot of code just to change a link, which seems like an overkill.
Another solution involves overriding AdminSite
. AdminSite
has a property called site_url
, and it seems like changing it would do the job. So, in essense, you can do something like this:
your_app/admin.py
from django.contrib.admin import AdminSite
from .models import MyModel
class MyAdminSite(AdminSite):
site_url = 'https://yourdomain.com'
admin_site = MyAdminSite(name='myadmin')
your_project/urls.py
from django.conf.urls import url
from myapp.admin import admin_site
urlpatterns = [
url(r'^myadmin/', admin_site.urls),
]
And you should register all your models with your custom admin, not Django’s default:
from your_app.admin import admin_site
admin_site.register(MyModel)
- [Django]-Remove default apps from Django-admin
- [Django]-Different initial data for each form in a Django formset
- [Django]-How can I call a custom Django manage.py command directly from a test driver?
4👍
Default link to viewsite is http://127.0.0.1:8000/
We can change it to custom url through register it in admin.py
admin.site.site_url = "/mySite"
Example : admin.py
from django.contrib import admin
from auth_app.models import profile
# Register your models here.
admin.site.register(profile)
#register link
admin.site.site_url = "/mySite"
- [Django]-Create a field whose value is a calculation of other fields' values
- [Django]-How can I obtain the model's name or the content type of a Django object?
- [Django]-Best practice for Python & Django constants
1👍
In admin.py, mention your custom path like following
admin.site.site_url = "/<Your Path>"
If your custom url is like "https://example.com/dashboard", You have to put below line in your admin.py
admin.site.site_url = "/dashboard"
- [Django]-AssertionError: `HyperlinkedIdentityField` requires the request in the serializer context
- [Django]-Django MySQL error when creating tables
- [Django]-How to make Facebook Login possible in Django app ?
1👍
You can change "VIEW SITE" link by changing "admin.site.site_url" which is "/" by default:
from django.contrib import admin
print(admin.site.site_url) # /
admin.site.site_url = "/example"
- [Django]-Heroku django app createsuperuser
- [Django]-How do I print out the contents of my settings in a django shell?
- [Django]-Anyone knows good Django URL namespaces tutorial?
1👍
You should keep in mind that if you are setting the reference (in either a template or in the .py file) it is going to build the url assuming that you gave it a relative component (/mything
becomes www.mysite.com/mything
). If you want to go to a completely different url you must include the "https://" and give the full url.
- [Django]-How can I save my secret keys and password securely in my version control system?
- [Django]-How can I chain Django's "in" and "iexact" queryset field lookups?
- [Django]-How do I get Django Admin to delete files when I remove an object from the database/model?
1👍
reverse
not work for urls route, you can config it like this:
from django.urls import include, path, reverse_lazy
admin.site.site_header = "MyAdmin"
admin.site.site_title = "MyAdmin"
admin.site.index_title = "MyAdmin Panel"
admin.site.site_url = reverse_lazy('dashboard:home')
- [Django]-No Module named django.core
- [Django]-How to set environment variables in PyCharm?
- [Django]-Set Django's FileField to an existing file