How do I use a pre-made app with my project? - python

sorry I'm a total noob but I can't find anywhere that actually explains this. I want to make a web blog, and I figured instead of rolling my own I would use a pre-made one, and I picked the blog from the basic apps project (https://github.com/nathanborror/django-basic-apps). I installed everything fine, added the apps to my settings file, synced the DB's, etc. But now I don't know what to do. How to I actually use the blog? When I run the test server it says I have to do manage.py startapp but I already have the app folder. What should I do? Again, sorry for the noob question.
Best,
Jake

Rule of thumb is: if app's documentary doesn't explain how to install (use, etc.) app, then its better to forget about using that app.
How can you rely on 5-month-not-updated-not-tested-not-well-documented app? There should be better solution.

Related

How to distribute Django web app to users?

I am developing a Django app to run on every client computer separately. The question is, which technologies should I use to distribute such as docker, virtual machine etc.? How can I protect the Django app's code? How can I prevent to distribute without licenses?
I suggest you look into Heroku. They have a free plan too so you can test it without having to pay first. Their guide with django after you set up an app is good too. You will find everything in their documentation but if you get stuck, I recommend this video by Corey Schafer. Good luck
Edit: Heroku also supports Docker but I'm not too familiar with it. Might be useful to you

What do I need to know to make a basic Django website?

As the title states, I am curious what I need to know to make a website with Django.
My Attempts:
I am familiar with Python, but despite my attempts to begin work on a webpage(attempted some Django tutorials online and purchased "2 Scoops of Django" and started to work with some of its recommendations) I always feel like it points me at something else to learn. (PostgreSQL, git, virtualenv, VirtualBox, Vagrant, and more.) I understand that some of these are tools I just need to implement, but I feel as if I could delve into these much further and don't understand when I should stop trying to learn more about these.
My Goal:
I want to be able to develop a webpage with Django, and understand the steps and tools I am implementing.
My Question:
What tools do I need to learn, and how much about them do I need to learn to be able to begin working effectively with Django?
This is a very broad question but I can try to answer it as clearly as possible.
You said you are familiar with Python, that's a good thing. The next thing you should know is the MVC framework that Django is based on and uses extensively.
You can refer to Django tutorial here: https://docs.djangoproject.com/en/1.9/intro/tutorial01/ (as already mentioned)
I can give you a TLDR of how this can work:
1. Create a django project : $ django-admin startproject mysite
2. In the file structure that is created, the most important things would be:
a. models.py - your database models or schema defined as classes and objects
b. views.py - the view you are trying to display (mainly rendering .html in your case)
c. settings.py - you path, app setting, permissions, etc
d. urls.py - how you will be calling your specific views (redirect urls)
Once you write a basic app, try to run it using $python manage.py runserver and voila!
For the website part, there a few easy ways. You can download twitter bootstrap and try to attempt a simple page that you can find online with django http://getbootstrap.com/2.3.2/
As far as technologies go:
venv: is so that you do not mess up your other python, etc versions on your laptop, it isn't necessary
git: this is something you should learn irrespective of a project requirement. There are basic 3 commands that will be enough.
You might have to learn basics of HTML and CSS for manipulating your own website. Most of the backend can be handled on Django using objects of models you created.
Try these things out and let me know if you need anymore information.

what literally defines a django app?

I have read a few questions about what an "app" is supposed to mean in django, but they go into the general purpose/use of an app, which is important, but not what an app literally "is". For example, I felt my curiosity today when
I deleted a folder that I installed as an app with django-admin startapp, and received a certain error that stackO told me was due to a deleted app name residing in my INSTALLED_APPS. After clearing the name, my app worked again
When making a folder cold (just mkdir, no startapp) in the highest level of a project, when trying to import names from real apps, I have to add my project to the sys.path list to be able to import. After remaking this folder as an app, imports are no longer an issue
I've read questions about this topic that had comments like "OK, I've got a models.py file, so it's an app", and it seems like very few people really understand how an app is started.
My question is,
what leeway do I have to modify the apps django makes? Can I delete all the files that come with it (except init) and make it a cold library with no views and models? Are any files besides init required to function correctly?
What does django do when I run startapp that causes an app to be importable automatically, which effect is not there when I make a folder with an init in it (as I said about needing to add the project path to sys.path within that folder). In other words, what does the django command "startapp" actually do to register an app? The action is in django.core.management.templates.py, I read it today and saw things in TemplateCommand.handle() that refer to app or project names, but couldn't see exactly how it registers them. It imports sys, but searching "sys.module" isn't in the file
If I want to turn an empty directory with init into an app, what do I have to do in the shell to make this change without doing startapp?
Thank you
TLDR: Django apps are just Python packages within your project, and you don't need any file except for __init__.py to import it.
I also experienced this vague explanation of "app" from the Django docs, and it led me to look into what a "web app" in the general scheme was before I could understand the concept of a Django one when I was starting out.
Generally defined, a web application is any program transferred from server to client via a browser. This could be an entire website, a certain component in a website (think captchas, widgets, OAuth, etc.), or a function of a website (such as integration with other technologies, like exporting a page to a PDF). These can be modular components or not, portable or not, and distinct within the project's source code or mixed with other things.
Since the general "web app" definition is quite ambiguous, it may be easier to imagine the "Django app." Your project contains one or more apps, of which some may have files or not. Technically, your app can contain nothing except the __init__.py and still be imported (it's just a normal Python package, albeit a useless one). You can make it a library with other modules, but this seems unpythonic, and I make a point to separate business logic from my website source code whenever possible.
Apps are simply things that do something for your project. A question that many people, including myself, like to ask to define an app, is "what does it do?" If you can't answer this question in a concise manner (that doesn't include "and") then your app could be broken into several different parts. This is recommended for your sake, but you may break this rule if you really want. In my first Django project, I made the entire website inside one app folder. It became a nightmare to manage, but I did it.
Views and models are just places to store the information that you need to use for that app in one place; if there was just one big app for your entire website, things would get cluttered and unmanageable very quickly. That would certainly be unpythonic, and the Django developers are very conscious of making things "correctly."
As for technical specifics, Django projects are packages. You can play around with manage.py startproject and checking your sys.path before/after. Apps are packages as well, which (supposedly) contain modules that allow your "app" to perform its intended function. You can use them for anything, everything, or nothing at all, but they are just a Python package with modules in a neat little folder on your system to do something for your project.
You can find a quick overview of applications in the Django documentation here, if you haven't already. Also, this is all a product of my base understanding, so if there is any problem with any part of my answer, please let me know.

How to deploy codenode

Aloha everyone,
So I was hoping to deploy codenode 'http://codenode.org/', on my website nested within a page. For the life of me I just can't follow the documentation and figure out what I'm supposed to do.
It only ever seems to talk about running things locally from the terminal, how are you supposed to set it up with regards to views, models and templates?
Thanks in advance.
They're simply telling you to install it via pip and virtualenv. This isn't terribly difficult to do on a host that is very Django and Python friendly, such as WebFaction. You can always put the necessary files where they need to go so that they will be added to your Python path via FTP, etc.

What's your folder layout for a Flask app divided in modules?

I am experimenting with Flask coming from Django and I really like it. There is just one problem that I ran into. I read the flask docs and the part about big applications or something like that and it explains a way to divide your project in packages, each one with its own static and templates folder as well as its own views module. the thing is that I cannot find a way that works to put the models in there using SQLAlchemy with the Flask extension. It works from the interactive prompt to create the tables, but when i use it inside the code it breaks. So I wanted to know how more experienced Flask developers solved this.
While I'm not ready to announce because I'm still actively working on refining the samples, you would probably benefit from the flask-skeleton project that I'm developing. I got tired of reinventing the wheel with regards to bootstrapping Flask websites so I started to a complete sample project that uses my best practices. I haven't added any unit tests yet, but this should be good enough for you to start with. Please send me feedback or suggestions if you come across any.
https://github.com/sean-/flask-skeleton/
Actually I found out what I was looking for. Instead of importing flaskext.sqlalchemy on the main __init__ you import it in the model. After that you import the model in the main __init__ and with db.init_app() start it and pass the app configurations. It is not as flexible as the skeleton shown in #Sean post, but it was what I wanted to know. If i weren't toying around probably the skeleton would be the one I'd use.

Categories