run 2 websites in one django project - python

First of all I have found several solutions for my problem but no one fits. So i use Django 1.5 + Python 3.3 + Gunicorn + Nginx as webserver.
My Django project directory look like:
fv/
frontend/
static/
templates/
index.html
models.py
views.py
fv/ -- this is only a folder where logic calculating files are stored
media/
static/
manage.py
settings.py
urls.py
wsgi.py
Now I would like to have the app homepage like frontend but these two apps should be like a standalone website which different domains like www.homepage.com and www.frontend.com. But they should use the same model, because the only model table I would like to share is the Django user model. And every app should have his own template files and urls.py.
I've already read the Django sites framework documentation but i have no idea how to redesign my project dir and arrange other necessary parts like the settings.py, urls.py.
I hope anyone could help me? :)

Related

Flask-Admin: How to use a different templates directory than the default?

My application is a backend REST API. I would like to add Flask-Admin, but only for use in nonprod.
I would like to keep the Flask admin related stuff separate from the rest of my application, in its own directory.
However, by default Flask Admin is using the same templates directory that my application would use.
How can I instruct Flask Admin to use a non-standard templates directory?
My app structure currently looks like this. In order to customize Flask-Admin, I need to create a templates/admin/ inside of my main api directory, which I don't want:
myapp/
myapp/
api/
app.py # Flask(__name__) defined here
views.py
templates/
admin/
index.html
admin/
myadmin.py
I instead want the Flask-Admin related things like the templates/admin/ directory under the admin directory, like this:
myapp/
myapp/
api/
app.py # Flask(__name__) defined here
views.py
admin/
myadmin.py
templates/
admin/
index.html
Is it possible to have Flask Admin use a non-standard templates directory?

connecting multiple create-react-apps with django

I have one big Django project consisting out of several small apps, independent from each other but partly sharing the same database or/and models.
All the apps are created with python manage.py startapp myappa so they have their own urls.py and views.py.
I started using create-react-app for the front end for two of those apps and connected them successfully by turning the index.html of the react project into a template and serve it through the views.py (more here).
Now each one of these create-react-app projects has its own build folder which's path I include in the STATICFILES_DIRS in settings.py to collect the static files.
It looks like this:
static/
templates/
myappa/
build/
static/
index.html
...
myappb/
build/
static/
index.html
...
Now, I was wondering if there is a way to have only one build folder that contains all built files respectively to their projects something like:
myappa/
myappb/
static/
templates/
build/
myappa/
static/
index.html
...
myappb/
static/
index.html
...
I'm imagining that this folder would live on the same level as the the static folder and the appa and appb folders.
One way, since by default I can't have the build folder outside the project folder structure(?) and I don't want to eject the project, I manually move all the build folders a couple of levels up so that it is on the same level as the app folders after the build process. That way I only have to include one path into to STATICFILES_DIRS. But I'm wondering if there is an automatic way of doing this.
I've been looking at other projects of django and React but unfortunately, most are rather small so they don't cover this case.
I was wondering if anyone had the same thoughts or maybe some nice big projects on github I can have a look at? Or am I wrong and by default having its own create react app in the separated apps makes sense?

Where is "views.py"

Him I am trying to set up my first django project. I have never done Django before so I don't know anything about it. I am trying to follow the official Django tutorial page, it tells me to open views.py. I can't find it anywhere in my "mysite" folder. In it, I have manage.py , db.sqlite3, __init__.py, settings.py, urls.py and wsgi.py along with the pycache folder, but no signs of views.py. Can anyone help me?
Running this command in console django-admin startproject myfirstproject will create a new django project for you, which will have another sub-folder named same as your project name. By default on creating a new project, the views.py file isn't created you have to create it manually in your project sub-folder.
To create a new app, Run django-admin startapp myapp which will create a new sub-folder under your parent directory which will have views.py where you can write your own custom views for your HTML templates

Django. Why do admin templates go in base folder instead of mysite?

I'm following the django tutorial, and I don't understand why put the templates folder for the admin pages in the base directory, instead of having it in mysite directory.
In fact, when adding templates to the polls app, these were put in the polls directory. Is there an underlying reason for this to happen? Will I run into trouble if I change this configuration?
An issue I ran into once with putting templates in apps’ template directories was that the template loader would use the first template it found by looping through the INSTALLED_APPS setting, so if your app comes after the admin app in the list (which it probably does), templates overriden there won’t be used.

Adding a second project to a Django project

I'm new to Django. I'm using Django with Eclipse. I've created a Django project using Eclipse (called "Django_Test_Project"). I've also created a PyDev project outside of Eclipse, using the command line (called "polls"). It has models.py, views.py, and tests.py.
I created "polls" using the following command:
manage.py startapp polls
I want use Eclipse to add "polls" as a second project to "Django_Test_Project". How do I do that with a project that was created outside of Eclipse? Eclipse doesn't recognize "polls" as a project, probably because the project files are missing in "polls".
Any help is appreciated. Thanks.
You are working on the Django tutorial, right? First of all, your terminology is not correct. You confuse a project with an application or app for short. It's no surprise that Eclipse doesn't recognize polls as a project, because it's not a project but an app.
In Django 1.4.1, the standard structure for a project called mysite is this:
mysite/
manage.py
mysite/
__init__.py
settings.py
urls.py
wsgi.py
Your polls app should go in the same directory where the file manage.py is located:
mysite/
manage.py
polls/
__init__.py
models.py
tests.py
views.py
mysite/
__init__.py
settings.py
urls.py
wsgi.py
You can just move the polls directory into the mysite directory using the Windows Explorer, Finder, Terminal etc. (depends on which OS you are running on). After refreshing the project view in Eclipse, your polls app should show up. In any case, you should read the Django tutorial more carefully as it basically answers your question already.
Additionally, take a look at this thread that explains the difference between projects and apps in a bit more detail.

Categories