Django admin site lost all its formatting - python

I change my computer and I migrated my django project just by copying the directory created by django-admin create project from the old computer to the new one. I installed all required modules in the new computer (including django) under a new Python virtual environment, and everything worked perfectly, but the admin site of the project, that shows in plain html with no styling at all.
I don't know how to fix it

This happened to me when I transferred the project to the production server for the first time. I don't know if you are using runserver or is your new computer hosting the project with Apache or Nginx. If it is the latter try the following command on the project root directory.
python manage.py collectstatic
Beware that you also need to specify the STATIC_ROOT and STATICFILES_DIRS in the settings.py file in order for the above command to work.
Refer to the django docs in order to learn more about working with static files in Django.

Related

django development show plugin (DjangoQLSearchMixin) but not in production

I have a develop env (local run on windows pycharm terminal with --insecure set) that is working properly with this plugin DjangoQLSearchMixin - I can see it on the search engine.
But for some reason it is not activated on the production admin panel (nginx + ubunto + django).
Django version and plugin are the same.
The code is the same, not sure what went wrong.
Maybe I need to recreate static files ?
Suggestions ?
Fixed by recreating the statis css files
python manage.py collectstatic
Thanks.

Do I need to call 'django-admin.py startproject PROJECT' command to start a new Django project?

I'm starting a new Django project using google cloud and Bitnami Django distribution.
I copied a working project from my local machine to a cloud instance to a projects folder, restarted Apache, but unfortunately, I cannot see my site from outside.
According to the documentation, to start a new project I need to run a command django-admin.py startproject PROJECT
Do I need to run this command for a copied project?

'Manage.py behave' not recognised as command in Django project

I've had to clone a repository involving a django project.
This is my first time using django and the project is configured a bit differently than what a normal django project would be. For instance it has a settings folder with a local.py file that contains a Local(Dev) class. I have installed behave_django, however when I run the command 'manage.py behave' it says that the command is not recognised.
Therefore I believe that whilst I have added INSTALLED_APPS = ('behave_django',) to the local.py file it is not getting recognised. I have tried adding it outside the class and within. Is there a way I can run a script to check my list of installed_apps, etc. Also I am new to python and the configuration side has gotten me a bit confused.
You need to provide the --settings option so Django knows you wish to use a different settings file with your task
manage.py behave --settings=myapp.local

How to run an django app which is not under the current project?

Actually , I want to run the app which are not in the current project directory. Is it possible to run another app if i give a path to that folder.
Currently i have a project directory PROJECT, under it there is manage.py and PROJECT--->settings.py,urls.py.
And I have an another app running at other directory, for example plugins-->App1, App2.
What i want, when i start the server in PROJECT directory. I want to dynamically configured the settings.py and urls.py of the current project, so that i can run other apps. If some one know how to deal with this type of problem please help me.
Yes, you can. The path to your app in INSTALLED_APPS is any valid python path.
A tuple of strings designating all applications that are enabled in this Django installation. Each string should be a dotted Python path to:
an application configuration class, or a package containing a
application.
Docs: link

Running the Django REST framework quickstart tutorial

I'm new to python and didn't use django before. I want to run the Django REST framework quickstart tutorial so I can use it for testing another application (http://django-rest-framework.org/tutorial/quickstart.html).
I ran in two issues:
1) I'm confused at the "Settings" step, I don't know what file is the listing suposed to be in. (I pasted the contents in urls.py, then I tried with a settings.py in the same folder as the other files.)
2) Just before the "Testing our API" section, I don't know the command to launch the project. (I tried "python urls.py" because url has references to the other files.)
Thank you.
Before you start using the django-rest-framework, you may want to learn more about django itself, so try the django tutorial.
https://docs.djangoproject.com/en/dev/intro/tutorial01/
About your question: when you start a project in django, it contains a settings.py.
Inside this file you have to edit the INSTALLED_APPS Tuple adding 'rest_framework,' in the end of it (one line before ")") and putting
REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': ('rest_framework.permissions.IsAdminUser',),
'PAGINATE_BY': 10
}
in the end of the file.
To launch the project you have to sync the database first, so do python manage.py syncdb, and once you did this call python manage.py runserver
settings.py obviously
python manage.py runserver
urls.py is an important file that manages the mapping of urls to the executables, but it's not an entry point to the django. manage.py provides tons of functionality and even able to run development server for you. In short, read the manual :)

Categories

Resources