I am trying to make an admin panel that includes some database. I have used flask-admin to automatically generate admin panel. When I ran the server locally in my PC, the bootstrap swatch is loading and works fine. However, when I hosted it in pythonanywhere and ran, it shows that the CSS is not found as shown in the image.
I have not used any templates of my own for admin panel. I used the following code to automatically generate the template.
admin = Admin(app, name='Admin Panel', template_mode='bootstrap3')
Link for the error message.
Same happened to me, but it turned out I used an unsupported swatch, here is the code that worked
app.config['FLASK_ADMIN_SWATCH'] = 'flatly'
# Create admin with custom base template
admin = admin.Admin(app, name='XXX', template_mode='bootstrap4')
Related
Homepage doesn't load properly
I have successfully build and deployed my code in Heroku.
It works fine locally but react doesn't render the index.html
The backend API works properly here
but the homepage here doesn't load - using ReactJS.
My all GitHub codes are here inside the develop branch.
Followed this post steps to host the same.
The homepage does not have a proper URL or path defined.
For example, you can go here:
https://mangya.herokuapp.com/administrator/
Or here
https://mangya.herokuapp.com/api
...As they are valid URLs.
Your blank 'homepage' path is not listed so there is no view being hit thus you get the error.
To fix this you need to change your urls.py in MyBlog to look like this:
urlpatterns = [
path('', [path.to.your.view]),
path('administrator/', admin.site.urls),
path('api/', include(router.urls))
]
In Django for anything to be rendered when you hit a URL, you need to have a view defined that renders the template, this is what my example for your urls.py shows.
So for example, if you are trying to run a Vue, React, or any other frontend framework that would rely on an API and Ajax calls to populate a page, you must allow that base page to be rendered by Django as it is the server running your application.
I have a Flask-Admin project set up with Flask-Security as well. It is pretty much https://pythonhosted.org/Flask-Security/quickstart.html#id1 but just more advanced. I can access the login page at localhost/login and logout and localhost/logout. The logging in and logging out works.
The templates for Flask-Admin works and everything is displayed as I'd expect. However, there are no templates on my machine or docker container where the Flask-Admin app is run. I installed Flask by running pip install Flask-Admin. I know I can over ride the security log in by adding something like
SECURITY_LOGIN_USER_TEMPLATE = 'security/login_user.html'
to the config file and uploading to /templates/security/login_user.html. There is also using
{%extends base.html}
to have a common theme. Should I have template files already in my project?
Flask Security have a default login template, if you want to use your own template for login or register follow these steps:
Create in template folder the a subfolder named security
Add your html documents to this folder
Go to your flask configuration and add the following settings:
If your want the register functionality
SECURITY_REGISTERABLE = True
Add the name of your templates:
SECURITY_LOGIN_USER_TEMPLATE = 'security/login.html'
SECURITY_REGISTER_USER_TEMPLATE = 'security/register.html'
Remember to use the appropriate form in login.html and in register.html, usually causes doubts but is simple:
register.html: register_user_form.field
login.html: login_user_form.field
These are the configurations for this work correctly.
this repository can you to see and understand better doubt:
I want to integrate AdmineLTE to my django project, with the help of its
README file.
https://github.com/StephenPCG/django-adminlte-templates
I followed all steps required in the file, but when I'm running my app, and want to login, I'm getting the following error.
You're using the staticfiles app without having set the required STATIC_URL setting.
which come from here
django-adminlte-templates/AdminLTE/templatetags/AdminLTE.py in <module>
bootstrap_url_base = _bootstrap_url_base if _bootstrap_url_base else static('bootstrap')
I am deploying a website that has an /admin/ page where staff and the superuser access the database tables.
In settings.py I changed these settings to put the site into production mode.
DEBUG = False
TEMPLATE_DEBUG = False
Issue is this has caused my admin site to show only black links on the applications where i cannot view, edit or add rows to the tables even if logged in as a super user.
What settings have i got wrong?
I found the solution here in this self answer:
django on apache - admin page links are VISIBLE but not CLICKABLE
Issue is i should be using a separate admin.py file, not putting things that should be in there in the model.py file.
web2py application administration is by default located on:
http://127.0.0.1:8000/admin/default/site
Is it possible to change "admin" to be something else (for example):
http://127.0.0.1:8000/appadmin/default/site
and if it is possible how that is achieved?
admin is just an app.
On windows open windows explorer and go to \web2py\applications\ right click on "admin" folder an then click in rename.
On Linux.
cd path/to/web2py/applications
mv admin newadmin
This answer is correct, but more changes needs to be done.
In your case, to change url from /admin to /appadmin do following steps
Rename admin app folder name to appadmin
Fix broken links to admin app
In your_app/controllers/appadmin.py, search all links to admin app and replace it with links to appadmin app
Change creation of links to error pages
Update routes.py, to route errors to appadmin app and not admin app
For detailed steps read How to change admin app url in web2py?